无法理解以下c ++代码行

she*_*n90 1 c++ opencv

我是C++的新手,并尝试弄清楚这行代码的含义:

cur_rect = cv::Rect(cur_rect) & cv::Rect(0, 0, mat->cols, mat->rows); // here
if( cv::Rect(cur_rect) == cv::Rect() )  //here
{
.......
}
Run Code Online (Sandbox Code Playgroud)

TaZ*_*TaZ 8

Rect & Rect部分与两个矩形相交,并在两个输入重叠时返回一个非空矩形.

因此,您可以比较结果以Rect()查看是否存在交叉点.您的代码裁剪cur_rect(0, 0, mat->cols, mat->rows)然后检查它是否为空.

资料来源:

http://opencv.willowgarage.com/documentation/cpp/core_basic_structures.html?highlight=rect

如何轻松检测2个ROI是否与OpenCv相交?

编辑

另一种实现方式,更清洁:

// crop cur_rect to rectangle with matrix 'mat' size:
cur_rect &= cv::Rect(0, 0, mat->cols, mat->rows);
if (cur_rect.area() == 0) {
    // result is empty
    ...
}
Run Code Online (Sandbox Code Playgroud)