【发布时间】:2013-07-22 13:14:41
【问题描述】:
我有 2 个多边形的轮廓(作为 cv::Point2d 的向量)。
我想计算它们之间的相交面积
获得它的最简单方法是什么?
非常感谢!
罗恩
【问题讨论】:
标签: c++ opencv geometry polygons
我有 2 个多边形的轮廓(作为 cv::Point2d 的向量)。
我想计算它们之间的相交面积
获得它的最简单方法是什么?
非常感谢!
罗恩
【问题讨论】:
标签: c++ opencv geometry polygons
最简单的编码方法如下:
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++;
【讨论】:
你可以找到与Clipper library相交的多边形
//create clipper polygons from your points
c.AddPolygons(subj, ptSubject);
c.AddPolygons(clip, ptClip);
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);
【讨论】:
在两个图像中用CV_FILLED 绘制形状,然后对它们进行AND。区域为:CountNonZero(bitwise_and(ShapeAImage,ShapeBImage))。
【讨论】: