diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index b170e6a4e4..5e2e952954 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -462,7 +462,11 @@ enum { COLOR_BGR2BGRA = 0, COLOR_COLORCVT_MAX = 139 }; - +//! types of intersection between rectangles +enum { INTERSECT_NONE = 0, + INTERSECT_PARTIAL = 1, + INTERSECT_FULL = 2 + }; /*! The Base Class for 1D or Row-wise Filters @@ -1415,7 +1419,7 @@ CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType, CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist ); //! computes whether two rotated rectangles intersect and returns the vertices of the intersecting region -CV_EXPORTS_W bool rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ); +CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ); CV_EXPORTS Ptr createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); diff --git a/modules/imgproc/src/intersection.cpp b/modules/imgproc/src/intersection.cpp index 9c1fd9f565..7870f78299 100644 --- a/modules/imgproc/src/intersection.cpp +++ b/modules/imgproc/src/intersection.cpp @@ -47,7 +47,7 @@ namespace cv { -bool rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ) +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 @@ -59,6 +59,8 @@ bool rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect1.points(pts1); rect2.points(pts2); + int ret = INTERSECT_FULL; + // Line vector // A line from p1 to p2 is: p1 + (p2-p1)*t, t=[0,1] for( int i = 0; i < 4; i++ ) @@ -91,7 +93,7 @@ bool rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& float t2 = (vx1*y21 - vy1*x21) / det; // This takes care of parallel lines - if( !std::isnormal(t1) || !std::isnormal(t2) ) + if( !std::isfinite(t1) || !std::isfinite(t2) ) { continue; } @@ -106,6 +108,11 @@ bool rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& } } + if( !intersection.empty() ) + { + ret = INTERSECT_PARTIAL; + } + // Check for vertices from rect1 inside recct2 for( int i = 0; i < 4; i++ ) { @@ -203,23 +210,12 @@ bool rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& if( intersection.empty() ) { - return false; + return INTERSECT_NONE ; } - //intersectingRegion.create(intersection.size(), 2, CV_32F); - - // Mat ret = intersectingRegion.getMat(); - Mat(intersection).copyTo(intersectingRegion); -// size_t step = !m.isContinuous() ? m.step[0] : sizeof(Point2f); - -// for( size_t i = 0; i < intersection.size(); i++ ) -// { -// *(Point2f*)(m.data + i*step) = intersection[i]; -// } - - return true; + return ret; } }