imgproc: fixed bug from intersectConvexConvex
Added checks for all of vertices from each contour instead of checking only for the first vertex.
This commit is contained in:
@@ -563,21 +563,41 @@ float cv::intersectConvexConvex( InputArray _p1, InputArray _p2, OutputArray _p1
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
if( pointPolygonTest(_InputArray(fp1, n), fp2[0], false) >= 0 )
|
||||
bool intersected = false;
|
||||
|
||||
// check if all of fp2's vertices is inside/on the edge of fp1.
|
||||
int nVertices = 0;
|
||||
for (int i=0; i<m; ++i)
|
||||
nVertices += pointPolygonTest(_InputArray(fp1, n), fp2[i], false) >= 0;
|
||||
|
||||
// if all of fp2's vertices is inside/on the edge of fp1.
|
||||
if (nVertices == m)
|
||||
{
|
||||
intersected = true;
|
||||
result = fp2;
|
||||
nr = m;
|
||||
}
|
||||
else if( pointPolygonTest(_InputArray(fp2, m), fp1[0], false) >= 0 )
|
||||
else // otherwise check if fp2 is inside fp1.
|
||||
{
|
||||
result = fp1;
|
||||
nr = n;
|
||||
nVertices = 0;
|
||||
for (int i=0; i<n; ++i)
|
||||
nVertices += pointPolygonTest(_InputArray(fp2, m), fp1[i], false) >= 0;
|
||||
|
||||
// // if all of fp1's vertices is inside/on the edge of fp2.
|
||||
if (nVertices == n)
|
||||
{
|
||||
intersected = true;
|
||||
result = fp1;
|
||||
nr = n;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (!intersected)
|
||||
{
|
||||
_p12.release();
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
area = (float)contourArea(_InputArray(result, nr), false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user