Hi,
I'm trying to compute the moments of the pixels found in a connected component of a gray scale image.
I have in a matrix cv::Mat contMat
a gray scale image. After thresholding it to another matrix binImg
, I found its connected components with cv::connectedComponents(binImg, lblImg, 8);
I went ahead and created a vector<cv::Point> points
with the points from a specific connected component, let's say the ones labeled 1, by traversing lblImg
and adding the points from contMat
that have label 1 in lblImg
.
Now I want to compute the image moments from those points in the contMat matrix using cv::moments(points, false)
, but that's not really working, because it seems moments expects a contour.
I'm wondering what's the best way to do this using OpenCV 3.1 in C++.
Thanks.