Search code examples
pythonopencvcomputer-vision

Detect the state/position of an object using computer vision


I need to check whether an object has moved to a specific location. (In my case it is the position of a motorized window shade). I want to use computer vision / image recognition for this.

For this I am thinking of comparing two images: The observed position vs the required position.

I did some search on openCv and found concepts like circle detection (to apply certain markings on the shade which I could use) or template matching, but not being a computer vision expert (I know python though) I would really appreciate a push in the right direction.

So I need some algorithm to check whether a shade is closed by comparing it to a referenced closed shade image, taken from the same angle etc, but taking into account some lighting variations..


Solution

  • The problem requires to compare the position an object in an image with a given static reference point.

    So first we need to determine the position of object which can be found as below as it single object is present in the image.

    As you are using python so you can follow these steps in opencv-python library:

    1) Load your image and binarize it.

    2) Use cv2.findContours(thresh, 1, 2) to find the contour of interest object.

    3) Find the bounding rectangle using cv2.boundingRect(cnt) function.

    4) Using rectangle coordinates find its center as representative point.

    5) Compare the centre with your reference point by calculaing the euclidean distance.

    This reference will be helpful.