Create instances of class Rect from opencv 3 in Py

2019-05-13 16:45发布

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 :)

1条回答
Ridiculous、
2楼-- · 2019-05-13 17:18

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)

查看更多
登录 后发表回答