Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何轻松检测OpenCv中是否有2个ROI相交?_C++_Opencv_Roi - Fatal编程技术网

C++ 如何轻松检测OpenCv中是否有2个ROI相交?

C++ 如何轻松检测OpenCv中是否有2个ROI相交?,c++,opencv,roi,C++,Opencv,Roi,我试图检测OpenCV中是否有两个感兴趣的区域(CvRects)彼此相交。很明显,我可以手动键入几个(或者说很多)要检查的条件,但这并不是一个好方法(imo) 有人能给我推荐其他的解决方案吗?OpenCV中有现成的方法吗 > P>我不知道C接口的任何现成的解决方案( CVCRT < /COD>),但是如果使用C++方式( CV:Rect< /Cord>),您可以很容易地说 interesect = r1 & r2; 矩形上的操作类型是 // In addition to the cl

我试图检测OpenCV中是否有两个感兴趣的区域(
CvRect
s)彼此相交。很明显,我可以手动键入几个(或者说很多)要检查的条件,但这并不是一个好方法(imo)


有人能给我推荐其他的解决方案吗?OpenCV中有现成的方法吗

> P>我不知道C接口的任何现成的解决方案(<代码> CVCRT < /COD>),但是如果使用C++方式(<代码> CV:Rect< /Cord>),您可以很容易地说

interesect  = r1 & r2;
矩形上的操作类型是

// 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)
bool cv::重叠roi(点tl1、点tl2、大小sz1、大小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

对。OpenCV中有一个现成的方法,用于OpenCV/modules/stitching/src/util.cpp

Hmmm。。。您可能知道如何将CvRect转换为cv::Rect吗?
rectr r=myCvRect难吗?我尝试了&运算符,但只得到了一个编译错误:
错误:成员的使用无效(您是否忘记了“&”?)
当我显然有一个&。
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;
}