首页 文章

openCV中2个多边形的交叉区域

提问于
浏览
6

我有2个多边形的轮廓(作为cv :: Point2d的向量) .

我想计算它们之间的交叉区域

获得它的最简单方法是什么?

非常感谢你!

罗恩

3 回答

  • 8

    在两个图像中使用 CV_FILLED 绘制形状并使用AND . 面积是: CountNonZero(bitwise_and(ShapeAImage,ShapeBImage)) .

  • 2

    最简单的代码编写方法如下:

    cv::Rect BoundingBox;
    int IntersectionArea = 0;
    //insert Min-Max X,Y to create the BoundingBox
    
    for (every y inside boundingbox)
         for (every x inside boundingbox)
             if (PointPolygonTest(x,y,Contour1) && PointPolygonTest(x,y,Contour2))
                 IntersectionArea++;
    
  • 1

    你可以找到交叉点多边形wth Clipper library

    //create clipper polygons from your points
    c.AddPolygons(subj, ptSubject);
    c.AddPolygons(clip, ptClip);
    c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);
    

    那么calc area of this polygon

相关问题