Reputation: 2688
Does someone have an idea to get the size and the position from an object? The Object is detected in a binary image with white pixels:
For example: Detected / Original
http://ivrgwww.epfl.ch/supplementary_material/RK_CVPR09/Images/segmentation/2_sal/0_12_12171.jpg http://ivrgwww.epfl.ch/supplementary_material/RK_CVPR09/Images/comparison/orig/0_12_12171.jpg
I know about the CvMoments
- Method. But I don't know how to use it in this case.
By the way: How can I make my mask more clearly?
Upvotes: 1
Views: 4469
Reputation: 2176
If the object is tree, you should delete small areas by using morphology as Astor written.
Alternative of finding mass, and mass center is using moments: http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=moments#moments
m00 as doc says is mass
There are also formulas for mass center.
This approach works when only your object remains on image after segmentation.
Upvotes: 1
Reputation: 8725
Simple algorithm:
findContours
to find all contours.countNonZero
or contourArea
to find area of each contour.Upvotes: 3