How to compute intersections of two contours
I have 2 contours and I want to compare how much the same are they, as the ratio of the area_of_c1/area_of_intersection
and area_of_c2/area_of_intersection
. I have done in a way of creating 2 convex contours and 2 Mat
s of zeros and fill them with fillConvexPoly()
and doing a bitwise_and()
between the two Mat
s for getting the intersection. Then I have counting the non zeros pixels for getting the areas and computed the ratios. Is there another more efficient way of computing the two ratios (like computing the intersection of two contours, or I do not know)?
Nope, what you are doing was exactly what I would have suggested.
Instead of a bitwes_and, I would suggest sum areas, with an image of 1's and an image of 2's (for example) and count 1's, 2's and 3's to get all areas in the same time. But nothing really better I'm afraid… ;-)