OpenCV Centroid of Irregular Shape

偶尔善良 提交于 2019-12-08 18:51:21

问题


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


回答1:


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.




回答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.



来源:https://stackoverflow.com/questions/12327791/opencv-centroid-of-irregular-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!