Circularity
- tomni.contour_operations.circularity(contour: numpy.ndarray) float [source]
Calculate the circularity of a contour.
The circularity of a contour is a measure of how closely it resembles a perfect circle. It is calculated based on the contour’s area and perimeter.
- Parameters
contour (np.ndarray) – The contour represented as an OpenCV ndarray.
- Returns
The circularity value, where 0 < circularity <= 1.
- Return type
float
Example
>>> contour = np.array([[[1, 2]], [[2, 3]], [[3, 2]], [[2, 1]]]) >>> circularity(contour) 0.7853981633974483 # Approximate circularity of a square.
Note
Formula: Circularity = (4 * π * area) / (perimeter^2)
Circularities close to 0 indicate more irregular shapes, while circularities close to 1 suggest shapes that closely resemble a perfect circle.