OpenCV Centroid of Irregular Shape
Asked Answered
H

2

7

how do you get the centroid of an irregular shape using OpenCV?

Hamza answered 8/9, 2012 at 3:33 Comment(1)
possible duplicate of OpenCV 2 CentroidDelisle
S
5

I'd recommend looking at the cv::Moments (C++) or cvMoments (C) function.

This StackOverflow thread gives some example code for a problem very similar to yours.

This post goes into some of the theory related to finding object center-points.

Subtotal answered 8/9, 2012 at 3:38 Comment(1)
thank you! opencv.itseez.com/doc/tutorials/imgproc/shapedescriptors/… helped me.Hamza
V
2

What do you mean by centroid?

If it's the center of mass, you can compute the average of the coordinates of the points that are inside your shape. But the center of mass can be outside the shape, for "irregular" (non-convex) shapes.

If you want the point inside the shape that is the further away to any of the contour point, you can have a look at distTransform function.

Volgograd answered 8/9, 2012 at 7:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.