Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenCV fitEllipse() for circle fitting

Is it valid to use OpenCV fitEllipse for circle fitting. fitEllipse() returns cv::RotatedRect how about averaging width and height to get fitted circle radius?

like image 272
krzych Avatar asked Dec 07 '12 09:12

krzych


1 Answers

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.
like image 140
Alessandro Jacopson Avatar answered Sep 18 '22 15:09

Alessandro Jacopson