我使用cv.rectangle绘制了一个矩形,并得到了一个轮廓形状(来自FindContours),矩形覆盖在轮廓上。
矩形与轮廓完全相交于两个点。如何找到矩形与轮廓轮廓线之间的这些交点?
我可以将两个图像叠加在一起并查找最大值,但我不知道矩形顶点是如何存储的,因为我需要一个填充有一组点的线类型向量。
谢谢
我使用cv.rectangle绘制了一个矩形,并得到了一个轮廓形状(来自FindContours),矩形覆盖在轮廓上。
矩形与轮廓完全相交于两个点。如何找到矩形与轮廓轮廓线之间的这些交点?
我可以将两个图像叠加在一起并查找最大值,但我不知道矩形顶点是如何存储的,因为我需要一个填充有一组点的线类型向量。
谢谢
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)
}