How can I get ellipse coefficient from fitEllipse function of OpenCV?

。_饼干妹妹 提交于 2019-11-27 20:19:52

The function fitEllipse returns a RotatedRect that contains all the parameters of the ellipse.

An ellipse is defined by 5 parameters:

  • xc : x coordinate of the center
  • yc : y coordinate of the center
  • a : major semi-axis
  • b : minor semi-axis
  • theta : rotation angle

You can obtain these parameters like:

RotatedRect e = fitEllipse(points);

float xc    = e.center.x;
float yc    = e.center.y;
float a     = e.size.width  / 2;    // width >= height
float b     = e.size.height / 2;
float theta = e.angle;              // in degrees

You can draw an ellipse with the function ellipse using the RotatedRect:

ellipse(image, e, Scalar(0,255,0)); 

or, equivalently using the ellipse parameters:

ellipse(res, Point(xc, yc), Size(a, b), theta, 0.0, 360.0, Scalar(0,255,0));

If you need the values of the coefficients of the implicit equation, you can do like (from Wikipedia):

So, you can get the parameters you need from the RotatedRect, and you don't need to change the function fitEllipse. The solve function is used to solve linear systems or least-squares problems. Using the SVD decomposition method the system can be over-defined and/or the matrix src1 can be singular.

For more details on the algorithm, you can see the paper of Fitzgibbon that proposed this fit ellipse method.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!