我有 2 个多边形的轮廓(作为 cv::Point2d 的向量)。
我想计算它们之间的相交面积
获得它的最简单方法是什么?
非常感谢!
罗恩
在两个图像中绘制形状,CV_FILLED
然后将它们与它们相结合。面积是: CountNonZero(bitwise_and(ShapeAImage,ShapeBImage))
。
您可以使用Clipper 库找到相交多边形
//create clipper polygons from your points
c.AddPolygons(subj, ptSubject);
c.AddPolygons(clip, ptClip);
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);
最简单的编码方法如下:
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++;