python get rect 函数,在Python中从opencv 3创建Rect类的实例

该博客指导读者在Python中使用OpenCV创建矩形,指出detectMultiScale返回的是(x, y, w, h)元组,需自行处理为Rect对象。建议利用Python列表或tuple功能来操作这些坐标数据,可能需要编写自定义函数来处理矩形操作。
摘要由CSDN通过智能技术生成

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

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值