Claudiu - 2 months ago 9x

Python Question

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.

Answer

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);
}
```

Source (Stackoverflow)

Comments