1 | initial version |

In 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`

:

However, because a circle has a maximal Area `A`

within a given perimeter `p`

, a scaling of roundness `k`

is performed:

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:

Moreover, eccentricity can be calculated from the central moments of second order:

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 I guess you can achieve your task. Furthermore, here there is an short 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.

2 | No.2 Revision |

In 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`

:

However, because a circle has a maximal Area `A`

within a given perimeter `p`

, a scaling of roundness `k`

is performed:

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:

Moreover, eccentricity can be calculated from the central moments of second order:

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 I guess you can achieve your task. Furthermore, here there is an ~~short ~~sort of example where it computes some of the above ~~properties ~~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.

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.