Ask Your Question

opencv-python>>Template Matching with Multiple Objects

asked 2018-05-24 12:28:50 -0500

chuan gravatar image

updated 2018-05-24 13:59:00 -0500

in the example,what does pt[0] and pt[1] mean??

for pt in zip(*loc[::-1]):
        cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

Umm...I guess it means initial point in the picture,but how do program know the initial point should be?

Can anyone help me to answer my question? Thank you in advance.

edit retag flag offensive close merge delete


link to the example ?

berak gravatar imageberak ( 2018-05-24 12:46:24 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-05-24 14:22:05 -0500

updated 2018-05-24 14:23:58 -0500

I assume you got the code from here

The result from zip(*loc[::-1]) is a tuple that is stored in pt. At this point, pt has the structure (x, y) and p[0] == x and p[1] == y.

Now, let's take a turn and look at OpenCV documentation of cv2.rectangle(). You will see that the third and fourth arguments are of type Point. A peek into Point shows that its attributes are x,y. In Python, this type definition is encapsulated into a tuple since data type declaration is not a thing.

I think this is enough for you to put two and two together and understand exactly what that drawing function does.

Happy coding, Cheers mate :)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-05-24 12:28:50 -0500

Seen: 350 times

Last updated: May 24 '18