【发布时间】:2012-01-03 14:55:10
【问题描述】:
我正在尝试检测 2 个感兴趣区域 (CvRects) 在 OpenCV 中是否相互交叉。我显然可以手动输入几个(或者说很多)要检查的条件,但这并不是一个很好的方法(imo)。
谁能建议我任何其他解决方案? OpenCV中是否有现成的方法?
【问题讨论】:
我正在尝试检测 2 个感兴趣区域 (CvRects) 在 OpenCV 中是否相互交叉。我显然可以手动输入几个(或者说很多)要检查的条件,但这并不是一个很好的方法(imo)。
谁能建议我任何其他解决方案? OpenCV中是否有现成的方法?
【问题讨论】:
我不知道有什么现成的C接口解决方案(CvRect),但是如果你使用C++的方式(cv::Rect),你可以轻松说
interesect = r1 & r2;
矩形操作的complete list是
// 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)
【讨论】:
Rect r = myCvRect;难吗?
error: invalid use of member (did you forget the ‘&’ ?) 显然我有一个 &。
bool cv::overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi)
{
int x_tl = max(tl1.x, tl2.x);
int y_tl = max(tl1.y, tl2.y);
int x_br = min(tl1.x + sz1.width, tl2.x + sz2.width);
int y_br = min(tl1.y + sz1.height, tl2.y + sz2.height);
if (x_tl < x_br && y_tl < y_br)
{
roi = Rect(x_tl, y_tl, x_br - x_tl, y_br - y_tl);
return true;
}
return false;
}
是的。 OpenCV中有一个现成的方法,在opencv/modules/stitching/src/util.cpp
【讨论】: