Ask Your Question

Revision history [back]

After finding the contours with cv::findContours(), you can use this function to retrieve the centroid of a blob.

cv::Point calculateBlobCentroid(const std::vector<cv::Point>& blob)
{
    cv::Moments mu = cv::moments(blob);
    cv::Point centroid = cv::Point (mu.m10/mu.m00 , mu.m01/mu.m00);

    return centroid;
}