OpenCV
4.5.4
Open Source Computer Vision
|
Prev Tutorial: Contour Features
Next Tutorial: Contours : More Functions
Here we will learn to extract some frequently used properties of objects like Solidity, Equivalent Diameter, Mask image, Mean Intensity etc. More features can be found at Matlab regionprops documentation.
*(NB : Centroid, Area, Perimeter etc also belong to this category, but we have seen it in last chapter)*
It is the ratio of width to height of bounding rect of the object.
\[Aspect \; Ratio = \frac{Width}{Height}\]
Extent is the ratio of contour area to bounding rectangle area.
\[Extent = \frac{Object \; Area}{Bounding \; Rectangle \; Area}\]
Solidity is the ratio of contour area to its convex hull area.
\[Solidity = \frac{Contour \; Area}{Convex \; Hull \; Area}\]
Equivalent Diameter is the diameter of the circle whose area is same as the contour area.
\[Equivalent \; Diameter = \sqrt{\frac{4 \times Contour \; Area}{\pi}}\]
Orientation is the angle at which object is directed. Following method also gives the Major Axis and Minor Axis lengths.
In some cases, we may need all the points which comprises that object. It can be done as follows:
Here, two methods, one using Numpy functions, next one using OpenCV function (last commented line) are given to do the same. Results are also same, but with a slight difference. Numpy gives coordinates in **(row, column)** format, while OpenCV gives coordinates in **(x,y)** format. So basically the answers will be interchanged. Note that, row = y and column = x.
We can find these parameters using a mask image.
Here, we can find the average color of an object. Or it can be average intensity of the object in grayscale mode. We again use the same mask to do it.
Extreme Points means topmost, bottommost, rightmost and leftmost points of the object.
For eg, if I apply it to an Indian map, I get the following result :