2012-01-03 14 views
15

Próbuję wykryć, czy 2 obszary zainteresowania (CvRect s) przecinają się nawzajem w OpenCV. Mogę oczywiście ręcznie wpisać kilka (lub raczej dużo) warunków do sprawdzenia, ale to naprawdę nie byłby dobry sposób na zrobienie tego (imo).Jak łatwo wykryć, czy 2 ROI przecinają się w OpenCv?

Czy ktoś może zaproponować mi jakieś inne rozwiązanie? Czy istnieje gotowa metoda w OpenCV?

Odpowiedz

28

ja nie znam żadnego gotowego rozwiązania dla interfejsu C (CvRect), ale jeśli używasz ++ drogę C (cv::Rect), można łatwo powiedzieć

interesect = r1 & r2; 

complete list operacji na prostokąty jest

// 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) 
+0

Hmmm ... może wiesz, jak mogę rzucić CvRect w cv :: Rect? – Patryk

+0

'Rect r = myCvRect;' Czy to trudne? – Sam

+0

Próbowałem & operator i dostaję po prostu błąd kompilacji: 'error: invalid use of member (zapomniałeś '&'?)' Kiedy wyraźnie mam &. – achow

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; 
} 

Tak. W OpenCV jest metoda gotowa do tego w opencv/modules/stitching/src/util.cpp

Powiązane problemy