轮廓和矩形OPENcv c之间的交点
发布时间:2020-12-16 07:32:39 所属栏目:百科 来源:网络整理
导读:我使用cv.rectangle绘制了一个矩形,并且有一个轮廓形状(来自FindContours),矩形被绘制出来. 矩形在两个点处与完整轮廓相交.如何在矩形和轮廓轮廓之间找到这些交点. 我可以将两个图像一起添加并查找最大值,但我知道如何存储矩形顶点,因为我需要一个填充了一组
我使用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) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |