10

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

我想计算它们之间的相交面积

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

非常感谢!

罗恩

4

3 回答 3

12

在两个图像中绘制形状,CV_FILLED然后将它们与它们相结合。面积是: CountNonZero(bitwise_and(ShapeAImage,ShapeBImage))

于 2013-07-23T13:58:31.813 回答
3

您可以使用Clipper 库找到相交多边形

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

然后计算这个多边形的面积

于 2013-07-23T13:46:14.533 回答
3

最简单的编码方法如下:

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++;
于 2013-07-23T13:04:07.997 回答