简体   繁体   中英

Create instances of class Rect from opencv 3 in Python

I would like to know how I can get an opencv rect object by providing two Points. The c++ version provides this datastructre.

http://docs.opencv.org/java/2.4.9/org/opencv/core/Rect.html

I cant find a way to instantiate rects in python. I tried cv2.Rect(p1,p2) but this method seems not be existent. Is it even possible?

Thanks in adavance :)

Look for example at this tutorial face detection http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html and you'll see that in Python opencv bindings rectangles are tuples/lists of the four coordinates - the results of, for example, faceCascade.detectMultiScale is a list of these - basically, use normal Python capabilities to manage them.

I guess you'll have to write your own overlap/area/contains functions - not terribly diificult - or see other answers here, for example Intersection and difference of two rectangles

UPDATE - my bad, the rectangles returned by detectMultiScale are (x,y,w,h)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM