Reputation: 229581
An ellipse of width 50, height 100, and angle 0, would be identical to an ellipse of width 100, height 50, and angle 90 - i.e. one is the rotation of the other.
How does cv2.fitEllipse handle this? Does it return ellipses in some normalized form (i.e. angle is picked such that width is always < height), or can it provide any output?
I ask as I'm trying to determine whether two fit ellipses are similar, and am unsure whether I have to account for these things. The documentation doesn't address this at all.
Upvotes: 1
Views: 2635
Reputation: 41775
You can see in the OpenCV source code for fitEllipse that the height of the ellipse is always larger than the width.
If the width is larger than the height, then width
and height
are swapped, and the angle
is corrected. box
is the RotatedRect
that defines the ellipse:
if( box.size.width > box.size.height )
{
float tmp;
CV_SWAP( box.size.width, box.size.height, tmp );
box.angle = (float)(90 + rp[4]*180/CV_PI);
}
Upvotes: 4
Reputation: 229581
Empirically, I ran code matching thousands of ellipses, and I never got one return value where the returned width was greater than the returned height. So it seems OpenCV normalizes the ellipse such that height >= width
.
Upvotes: 0