在Python中从opencv 3创建Rect类的实例 [英] Create instances of class Rect from opencv 3 in Python

查看:667
本文介绍了在Python中从opencv 3创建Rect类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何通过提供两个Point来获取opencv rect对象. C ++版本提供了这种数据结构.

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

我找不到在python中实例化rect的方法. 我尝试了cv2.Rect(p1,p2),但是这种方法似乎不存在. 可能吗?

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?

非常感谢:)

推荐答案

以本教程为例,例如面部检测 http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html ,您会发现在Python opencv绑定中,矩形是四个坐标的元组/列表-例如faceCascade.detectMultiScale的结果就是这些的列表-基本上,使用常规的Python功能来管理它们.

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

更新-不好的是,detectMultiScale返回的矩形是(x,y,w,h)

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

这篇关于在Python中从opencv 3创建Rect类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆