OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 20 Jun 2015 17:12:35 -0500How do i get the goodness of fit for the result of fitEllipse?http://answers.opencv.org/question/20521/how-do-i-get-the-goodness-of-fit-for-the-result-of-fitellipse/fit an ellipse and get goodness of fit
rRect = fitEllipse( Coords);
double angle = rRect.angle/180*Pi;
Point2f Center = rRect.center;
Size2f Sz = rRect.size;
g_GOF = 0; //Goodness Of Fit, the smaller the better
double posx, posy;
for(int i = 0; i < 32; i++){
posx = (Coords[i].x - Center.x) * cos(-angle) - (Coords[i].y- Center.y) * sin(-angle);
posy = (Coords[i].x - Center.x) * sin(-angle) + (Coords[i].y- Center.y) * cos(-angle);
g_GOF += abs( posx/Sz.width*posx/Sz.width + posy/Sz.height*posy/Sz.height - 0.25);
}
this works very well but comments are appreciatedWed, 11 Sep 2013 04:27:40 -0500http://answers.opencv.org/question/20521/how-do-i-get-the-goodness-of-fit-for-the-result-of-fitellipse/Comment by catacon for <p>fit an ellipse and get goodness of fit</p>
<pre><code>rRect = fitEllipse( Coords);
double angle = rRect.angle/180*Pi;
Point2f Center = rRect.center;
Size2f Sz = rRect.size;
g_GOF = 0; //Goodness Of Fit, the smaller the better
double posx, posy;
for(int i = 0; i < 32; i++){
posx = (Coords[i].x - Center.x) * cos(-angle) - (Coords[i].y- Center.y) * sin(-angle);
posy = (Coords[i].x - Center.x) * sin(-angle) + (Coords[i].y- Center.y) * cos(-angle);
g_GOF += abs( posx/Sz.width*posx/Sz.width + posy/Sz.height*posy/Sz.height - 0.25);
}
</code></pre>
<p>this works very well but comments are appreciated</p>
http://answers.opencv.org/question/20521/how-do-i-get-the-goodness-of-fit-for-the-result-of-fitellipse/?comment=38417#post-id-38417I agree this works very well, but could you explain it? I understand that finding the distance from a point to an arbitrary ellipse is a transcendental problem, which is the reason for your posx and posy calculations (transforming from an arbitrary ellipse to a centered, non-rotated ellipse). Why do you use the negative angle? Where does the -0.25 factor come from? Why use only 32 points?
Thanks!Wed, 30 Jul 2014 09:17:01 -0500http://answers.opencv.org/question/20521/how-do-i-get-the-goodness-of-fit-for-the-result-of-fitellipse/?comment=38417#post-id-38417Comment by cvandert for <p>fit an ellipse and get goodness of fit</p>
<pre><code>rRect = fitEllipse( Coords);
double angle = rRect.angle/180*Pi;
Point2f Center = rRect.center;
Size2f Sz = rRect.size;
g_GOF = 0; //Goodness Of Fit, the smaller the better
double posx, posy;
for(int i = 0; i < 32; i++){
posx = (Coords[i].x - Center.x) * cos(-angle) - (Coords[i].y- Center.y) * sin(-angle);
posy = (Coords[i].x - Center.x) * sin(-angle) + (Coords[i].y- Center.y) * cos(-angle);
g_GOF += abs( posx/Sz.width*posx/Sz.width + posy/Sz.height*posy/Sz.height - 0.25);
}
</code></pre>
<p>this works very well but comments are appreciated</p>
http://answers.opencv.org/question/20521/how-do-i-get-the-goodness-of-fit-for-the-result-of-fitellipse/?comment=64537#post-id-6453732 points is an arbitrary number, and in this case just the number of points I used in my call to fitEllipse.
If each point used to otain the fit is perfectly on the ellipse then:
1. (px/half_ellipse_width)^2 + (py/half_ellipse_height)^2 = 1
which follows from the definition of an ellipse if it's center is at 0,0. However, since i'm using full width and height, that is (2 x half_width)^2 and (2xhalf_height)^2, the result is 0.25 instead of 1.0.
equation 1, is defined for an ellipse with vertical and horizontal axes, whearas fitEllipse returns an ellipse that is rotated, using -angle rotates the positions back on to an ellipse with orthogonal axes.Sat, 20 Jun 2015 17:12:35 -0500http://answers.opencv.org/question/20521/how-do-i-get-the-goodness-of-fit-for-the-result-of-fitellipse/?comment=64537#post-id-64537