简体   繁体   English

在Python中从opencv 3创建类Rect的实例

[英]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. 我想知道如何通过提供两个点来获得opencv rect对象。 The c++ version provides this datastructre. c ++版本提供此数据结构。

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

I cant find a way to instantiate rects in python. 我无法找到一种在python中实例化rects的方法。 I tried cv2.Rect(p1,p2) but this method seems not be existent. 我尝试了cv2.Rect(p1,p2)但这种方法似乎不存在。 Is it even possible? 它甚至可能吗?

Thanks in adavance :) 感谢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. 在本教程的面部检测http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html中查看示例,您将看到在Python中opencv绑定矩形是四个坐标的元组/列表 - 结果例如,faceCascade.detectMultiScale是这些的列表 - 基本上,使用普通的Python功能来管理它们。

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) 更新 - 我的不好,detectMultiScale返回的矩形是(x,y,w,h)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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