【问题标题】:Intersection between contour and rectangle OPENcv c++轮廓和矩形OPENcv c ++之间的交集
【发布时间】:2012-10-05 12:28:04
【问题描述】:

我使用 cv.rectangle 绘制了一个矩形,并有一个轮廓形状(来自 FindContours),矩形被绘制在上面。

矩形在两点与完整轮廓相交。如何找到矩形和轮廓轮廓之间的这些交点。

我可以将两个图像加在一起并寻找最大值,但我知道矩形顶点是如何存储的,因为我需要一个填充了一组点的线型向量

谢谢

【问题讨论】:

    标签: c++ opencv intersection


    【解决方案1】:

    如果您确定矩形仅在 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)
    
    }  
    

    【讨论】:

    • 是的...谢谢它只会在两个位置融合...谢谢您的回答..我下周度假回来时会尝试一下
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2012-05-10
    • 2021-09-01
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多