In my other post, I examined the RotatedRect of minAreaRect() function. But later i found out that the ellipse/RotatedRect of minFitEllipse() function doesn’t work the same way as that of minAreaRect(). (Looks like the two developers didn’t talk to each other before developing these functions !)
So, i again examined the RotatedRect extraacted from ellipse of the minFitEllipse() function and here are the results:
- The angle property is the angle between vertical and the edge of 0th and 1st vertices of the rectangle.
- If the angle is less than 90 degrees the 0th vertex if the left most (or left-bottom if angle is 0 degrees) vertex. 1st, 2nd, 3rd vertices follow in clockwise manner.
- If the angle is greater than or equal to 90 degrees (but < 180), 0th vertex is the top most vertex (or top left vertex if angle == 90). 1st, 2nd, 3rd vertices follow in clockwise manner.
- Height is always greater than (or equal to) Width.
This is a code snippet i used to get and draw RotatedRect of fitellipse() function.
RotatedRect box = fitEllipse(contour);
Point2f vtx[4];
box.points(vtx);
for( int j = 0; j < 4; j++ )
line(drawing, vtx[j], vtx[(j+1)%4], Scalar(0,255,0),2);
Below are test cases for various test objects (in white). Green rectangle is the RotatedRect of fitEllipse() function.
Cases : 0 <= Angle < 90



Cases : 90 <=Angle < 180










