From 00f63fa8f7569fc03cc425ed838ad20f03006d2a Mon Sep 17 00:00:00 2001 From: Nghia Ho <nghiaho12@yahoo.com> Date: Wed, 31 Jul 2013 23:08:02 +1000 Subject: [PATCH] Finished test code, added image to the doc --- ...uctural_analysis_and_shape_descriptors.rst | 30 +++++++++++++++++++ modules/imgproc/src/intersection.cpp | 28 +++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst b/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst index 136d3e3df..763b45bc8 100644 --- a/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst +++ b/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst @@ -657,3 +657,33 @@ See below a sample output of the function where each image pixel is tested again .. [Suzuki85] Suzuki, S. and Abe, K., *Topological Structural Analysis of Digitized Binary Images by Border Following*. CVGIP 30 1, pp 32-46 (1985) .. [TehChin89] Teh, C.H. and Chin, R.T., *On the Detection of Dominant Points on Digital Curve*. PAMI 11 8, pp 859-872 (1989) + + + +rotatedRectangleIntersection +------------------------------- +Finds out if there is any intersection between two rotated rectangles. If there is then the vertices of the interesecting region are returned as well. + +.. ocv:function:: int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ) +.. ocv:pyfunction:: cv2.rotatedRectangleIntersection( rect1, rect2 ) -> retval, intersectingRegion +.. ocv:cfunction:: int cvRotatedRectangleIntersection( const CvBox2D* rect1, const CvBox2D* rect2, CvPoint2D32f intersectingRegion[8], int* pointCount ) + + :param rect1: First rectangle + + :param rect2: Second rectangle + + :param intersectingRegion: The output array of the verticies of the intersecting region. It returns at most 8 vertices. Stored as ``std::vector<cv::Point2f>`` or ``cv::Mat`` as Mx1 of type CV_32FC2. + + :param pointCount: The number of vertices. + +The following values are returned by the function: + + * INTERSECT_NONE=0 - No intersection + + * INTERSECT_PARTIAL=1 - There is a partial intersection + + * INTERSECT_FULL=2 - One of the rectangle is fully enclosed in the other + +Below are some examples of intersection configurations. The hatched pattern indicates the intersecting region and the red vertices are returned by the function. + +.. image:: pics/intersection.png diff --git a/modules/imgproc/src/intersection.cpp b/modules/imgproc/src/intersection.cpp index f0f00e2cd..f63f8230c 100644 --- a/modules/imgproc/src/intersection.cpp +++ b/modules/imgproc/src/intersection.cpp @@ -61,6 +61,34 @@ int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& r int ret = INTERSECT_FULL; + // Specical case of rect1 == rect2 + { + bool same = true; + + for( int i = 0; i < 4; i++ ) + { + if( fabs(pts1[i].x - pts2[i].x) > samePointEps || (fabs(pts1[i].y - pts2[i].y) > samePointEps) ) + { + same = false; + break; + } + } + + if(same) + { + intersection.resize(4); + + for( int i = 0; i < 4; i++ ) + { + intersection[i] = pts1[i]; + } + + Mat(intersection).copyTo(intersectingRegion); + + return 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++ )