The intersection area of ​​2 polygons in openCV

I have the contours of two polygons (like the cv :: Point2d vector).

I would like to calculate the area of ​​intersection between them

What is the easiest way to get it?

Thank you very much!

Ron

+4
source share
3 answers

Draw shapes using CV_FILLED on two images and AND them. Area: CountNonZero(bitwise_and(ShapeAImage,ShapeBImage)) .

+5
source

The easiest way for the code is as follows:

 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++; 
+2
source

You can find the polygon intersection wth Clipper Library

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

then calculate the area of ​​this polygon

+1
source

Source: https://habr.com/ru/post/1492949/


All Articles