[英]Intersection between contour and rectangle OPENcv c++
我已經使用cv.rectangle繪制了一個矩形,並且具有繪制矩形的輪廓形狀(來自FindContours)。
矩形在兩個點處與完整輪廓相交。 如何找到矩形和輪廓輪廓之間的這些交點。
我可以將兩個圖像加在一起並尋找最大值,但我確實知道矩形頂點的存儲方式,因為我需要用一組點填充的線型矢量
謝謝
如果確定矩形僅在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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.