501 - not implemented
501 - not implemented

Reputation: 2688

Get position and size of an object in a binary image

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

Answers (2)

krzych
krzych

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

ArtemStorozhuk
ArtemStorozhuk

Reputation: 8725

Simple algorithm:

  1. Delete small areas of white pixels using morphological operations (erosion).
  2. Use findContours to find all contours.
  3. Use countNonZero or contourArea to find area of each contour.
  4. Cycle throught all points of each contour and find mean of them. This will be the center of contour.

Upvotes: 3

Related Questions