diff --git a/modules/imgproc/include/opencv2/imgproc/imgproc_c.h b/modules/imgproc/include/opencv2/imgproc/imgproc_c.h index 4e2dc7142a..6417a00f38 100644 --- a/modules/imgproc/include/opencv2/imgproc/imgproc_c.h +++ b/modules/imgproc/include/opencv2/imgproc/imgproc_c.h @@ -615,6 +615,10 @@ CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage, CVAPI(void) cvFitLine( const CvArr* points, int dist_type, double param, double reps, double aeps, float* line ); +/* Finds the intersecting region made by two rotated rectangles. + If there is an intersection the vertices of the region are returned. */ +CVAPI(int) cvRotatedRectangleIntersection( const CvBox2D* rect1, const CvBox2D* rect2, CvPoint2D32f intersectingRegion[8], int* pointCount ); + #ifdef __cplusplus } #endif diff --git a/modules/imgproc/src/intersection.cpp b/modules/imgproc/src/intersection.cpp index 7870f78299..f0f00e2cd1 100644 --- a/modules/imgproc/src/intersection.cpp +++ b/modules/imgproc/src/intersection.cpp @@ -49,7 +49,7 @@ namespace cv int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ) { - const float samePointEps = 0.00001; // used to test if two points are the same, due to numerical error + const float samePointEps = 0.00001; // used to test if two points are the same Point2f vec1[4], vec2[4]; Point2f pts1[4], pts2[4]; @@ -213,9 +213,28 @@ int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& r return INTERSECT_NONE ; } + // If this check fails then it means we're getting dupes, increase samePointEps + CV_Assert( intersection.size() <= 8 ); + Mat(intersection).copyTo(intersectingRegion); return ret; } +} // end namespace + +int cvRotatedRectangleIntersection( const CvBox2D* rect1, const CvBox2D* rect2, CvPoint2D32f intersectingRegion[8], int* pointCount ) +{ + std::vector pts; + + int ret = cv::rotatedRectangleIntersection( *rect1, *rect2, pts ); + + for( size_t i=0; i < pts.size(); i++ ) + { + intersectingRegion[i] = pts[i]; + } + + *pointCount = (int)pts.size(); + + return ret; }