16

OpenCV で2 つの関心領域 ( CvRects) が互いに交差しているかどうかを検出しようとしています。明らかに、チェックするいくつかの (またはむしろ多数の) 条件を手動で入力できますが、それは実際には良い方法ではありません (imo)。

誰かが私に他の解決策を提案できますか? そのためのOpenCVの準備ができた方法はありますか?

4

2 に答える 2

31

C インターフェースの既製のソリューション ( CvRect) は知りませんが、C++ の方法 ( cv::Rect) を使用すると、簡単に言うことができます。

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)
于 2012-01-03T15:20:32.933 に答える
5
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/modules/stitching/src/util.cpp には、そのための OpenCV の準備完了メソッドがあります。

于 2014-06-24T22:22:03.473 に答える