how do you get the centroid of an irregular shape using OpenCV?
So, if you hang a shape from two different points (one at a time) and draw a line straight down from each point, the center of mass is where those lines intersect. This technique can be used for any irregular two-dimensional shape.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With