如何轻松地检测2个ROIs是否相交在OpenCv? [英] How can one easily detect whether 2 ROIs intersects in OpenCv?
问题描述
我试图检测2个感兴趣区域( CvRect
s)是否在OpenCV中相互交叉。我可以明显地手动键入几个(或相当多的)条件进行检查,但这不会是一个很好的方法来做它(imo)。
任何人都可以向我推荐其他解决方案?在OpenCV中有一个准备好的方法吗?
我不知道任何现成的解决方案的C接口( CvRect
),但是如果你使用C ++方法( cv :: Rect
),你可以很容易地说
interesect = r1& r2; /basic_structures.html?highlight=rect#Rect_\">完整列表的矩形操作是 //在除了类成员,在矩形上实现以下操作
//:
//(将矩形移动一定偏移量)
//(扩展或缩小矩形一定量)
rect + = point,rect - = point,rect + = size,rect - = size(augmenting operations)
rect = rect1& rect2(rectangle intersection)
rect = rect1 | rect2(rect2和rect3的最小矩形区域)
rect& = rect1,rect | = rect1(以及相应的扩展操作)
rect == rect1,rect!= rect1 $ b
I am trying to detect whether 2 Regions of Interest (CvRect
s) are intersecting one another in OpenCV. I can obviously manually type several (or rather a lot of) conditions to be checked but that wouldn't really be a good way to do it (imo).
Can anyone suggest me any other solution? Is there a ready method in OpenCV for that ?
解决方案 I do not know of any ready-made solution for the C interface (CvRect
), but if you use the C++ way (cv::Rect
), you can easily say
interesect = r1 & r2;
The complete list of operations on rectangles is
// In addition to the class members, the following operations
// on rectangles are implemented:
// (shifting a rectangle by a certain offset)
// (expanding or shrinking a rectangle by a certain amount)
rect += point, rect -= point, rect += size, rect -= size (augmenting operations)
rect = rect1 & rect2 (rectangle intersection)
rect = rect1 | rect2 (minimum area rectangle containing rect2 and rect3 )
rect &= rect1, rect |= rect1 (and the corresponding augmenting operations)
rect == rect1, rect != rect1 (rectangle comparison)
这篇关于如何轻松地检测2个ROIs是否相交在OpenCv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!