Ask Your Question

Revision history [back]

click to hide/show revision 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:

image description

However, because a circle has a maximal Area A within a given perimeter p, a scaling of roundness k is performed:

image description

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 image description

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

image description

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.

source

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:

image description

However, because a circle has a maximal Area A within a given perimeter p, a scaling of roundness k is performed:

image description

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 image description

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

image description

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.

source