2012-10-05 33 views
3

我繪製了一個使用cv.rectangle的矩形,並且有一個矩形繪製的輪廓形狀(來自FindContours)。輪廓和矩形之間的交集OPENcv C++

矩形與兩點處的完整輪廓相交。我怎樣才能找到矩形和輪廓輪廓之間的這些交點。

我可以在兩個圖像加在一起,尋找最大值,但我不知道該矩形頂點的存儲方式,因爲我需要充滿一組點的直線型矢量

感謝

回答

2

如果你可以確定你的矩形只有2個點的形狀,你可以迭代你的輪廓點,並檢查這些點是否在你的矩形邊界。

std::vector<cv::Point> shape; // computed with FindContours 
cv::Rect myRect; //whatever 

const int NUMPOINTS = 2; 
int found = 0; 
for(std::vector<cv::Point>::iterator it = shape.begin(); it != shapes.end() && found < NUMPOINTS; ++it) { 
    if (it->y == myRect.y && it->x >= myRect.x && it->x < myRect.x + width) 
    // that point cross the top line of the rectangle 
    found++; // you might want to store the point 
    else if (// ... add the other checks here) 

} 
+0

是......感謝它只會在兩個位置intesect ....感謝您的答案..我會下週嘗試,當我回來休假時 –