문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top