Using OpenCV fitEllipse() for circle fitting

a 夏天 提交于 2019-11-30 15:00:06

I think that the "validity" of using cv::fitEllipse for fitting circles depends on the precision you require for the fitting.

For example you can run your algorithm on a test set, fitting points with cv::fitEllipse and logging the length of the two axes of the ellipse, then have a look at the distributions of the ratio of two axes or at the difference between the major and the minor axis; you can find how much your supposed circles differ from a circle and then asses if you can use the cv::fitEllipse.

You can take the average of the width and the height of the cv::RotatedRect returned by cv::fitEllipse to get an approximation of the diameter of the circle (you wrote the radius but I think it was a trivial error).

You can have a look at this very readable article UMBACH, Dale; JONES, Kerry N. A few methods for fitting circles to data. Instrumentation and Measurement, IEEE Transactions on, 2003, 52.6: 1881-1885. and write your own circle interpolator.

If you want to minimize the geometric error (the sum of the squares of the distances from the points to the circle, as explained in the Introduction of the article) you maybe need a reliable implementation of a non linear minimization algorithm.

Otherwise you can write a simple circle interpolator with the formulae from (II.8) to (II.15) (a closed-form solution wich minimize an error different from the geometric one) with some warning:

  1. from an implementation point of view you have to take care of the usually warnings about roundoff error and truncation error.
  2. the closed form solution cannot be robust enough in case of outlier points, in that case you may need to implement a robust interpolator like RANSAC (random choose three points, interpolate a circle with that three points with formulae from (25) to (34) from Weisstein, Eric W. "Circle." From MathWorld--A Wolfram Web Resource, compute the consensus and iterate). This warning applies also to the circle found with the minimization of the geometric error.

There is a function for circle fitting: minEnclosingCircle

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