OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 16 Apr 2015 16:54:09 -0500Program that check for the roundness of ellipse?http://answers.opencv.org/question/59955/program-that-check-for-the-roundness-of-ellipse/In my program i am creating a ellipse which bounds some points. When the points are normal distributed, the ellipse turns into a circle, which means a mask has to be increased. But how do i check for the roundness of the bounding ellipse?Thu, 16 Apr 2015 06:55:08 -0500http://answers.opencv.org/question/59955/program-that-check-for-the-roundness-of-ellipse/Comment by thdrksdfthmn for <p>In my program i am creating a ellipse which bounds some points. When the points are normal distributed, the ellipse turns into a circle, which means a mask has to be increased. But how do i check for the roundness of the bounding ellipse?</p>
http://answers.opencv.org/question/59955/program-that-check-for-the-roundness-of-ellipse/?comment=59958#post-id-59958Have you tried the ratio between the 2 axes? If it is 1 (or very close to 1) than it is (may be) a circleThu, 16 Apr 2015 07:43:39 -0500http://answers.opencv.org/question/59955/program-that-check-for-the-roundness-of-ellipse/?comment=59958#post-id-59958Answer by theodore for <p>In my program i am creating a ellipse which bounds some points. When the points are normal distributed, the ellipse turns into a circle, which means a mask has to be increased. But how do i check for the roundness of the bounding ellipse?</p>
http://answers.opencv.org/question/59955/program-that-check-for-the-roundness-of-ellipse/?answer=60007#post-id-60007In order to obtain the roundness of an object, you either extract the roundness `k` or the eccentricity `e` of the object. With eccentricity being a better measure because it has a clearly defined range of values and therefore it can be compared much better.
The roundness `k` can easily be calculated by dividing the square of the perimeter `p` with the area `A`:
![image description](/upfiles/14292200479754853.png)
However, because a circle has a maximal Area `A` within a given perimeter `p`, a scaling of roundness `k` is performed:
![image description](/upfiles/1429220227900270.png)
Therefore, `k` for a circle is equal 1, while for other objects > 1. On the other hand eccentricity `e` can derived from the semi-major and semi-minor axes `a` and `b` of an object:
![image description](/upfiles/1429220377233756.png) ![image description](/upfiles/14292204229443596.png)
Moreover, eccentricity can be calculated from the central moments of second order:
![image description](/upfiles/14292205034965091.png)
The eccentricity can have values from 0 to 1. 0 corresponds to a perfectly round object while 1 to a line shaped object. Therefore using the [moments class](http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments) I guess you can achieve your task. Furthermore, [here](http://opentouch.googlecode.com/svn/trunk/src/Examples/cvBlobDetection/blobdemo2.cpp) there is an sort of example where it computes some of the above properties. it is in old C api but I do not think that it would be that hard to port it to the new C++ api.
[source](http://www.google.dk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&ved=0CEAQFjAF&url=http%3A%2F%2Fcfile7.uf.tistory.com%2Fattach%2F210E193853E08FC026EDA4&ei=dCUwVdTuKITSyAOZxoGwAQ&usg=AFQjCNFUIKXvnVWFGt49r_jG7xsG3u90eg&sig2=Da8_Nb-LfWEJhWc1VYb8XA&bvm=bv.91071109,d.bGQ&cad=rja)Thu, 16 Apr 2015 16:54:09 -0500http://answers.opencv.org/question/59955/program-that-check-for-the-roundness-of-ellipse/?answer=60007#post-id-60007