Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 轮廓线和矩形OPENcv c+之间的交点+;_C++_Opencv_Intersection - Fatal编程技术网

C++ 轮廓线和矩形OPENcv c+之间的交点+;

C++ 轮廓线和矩形OPENcv c+之间的交点+;,c++,opencv,intersection,C++,Opencv,Intersection,我用cv.rectangle绘制了一个矩形,并绘制了一个轮廓形状(来自FindContours) 矩形在两点处与整个轮廓相交。如何在矩形和轮廓轮廓之间找到这些交点 我可以将这两个图像相加并查找最大值,但我确实知道矩形顶点是如何存储的,因为我需要一个填充有一组点的线型向量 谢谢如果您确定矩形仅在两个点穿过形状,您可以迭代通过轮廓点,并检查这些点是否在矩形边框中 std::vector<cv::Point> shape; // computed with FindContours cv:

我用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)

}  
std::向量形状;//用FindContours计算
cv::Rect myRect//无论什么
常量int NUMPOINTS=2;
int=0;
for(std::vector::iterator it=shape.begin();it!=shapes.end()&&foundy==myRect.y&&it->x>=myRect.x&&it->x
是的……谢谢,这将只在两个地点进行访问……谢谢你的回答……我将在下周度假回来后试一试