Finding centroid of image with opencv

Hi all, does anyone know of an opencv function for finding the centroid of a greyscale mage? I am currently doing it manually by looping through all pixels, and taking weighted average of all positions, but I was wondering if it can be done with a single function (which would take advantage of intel optimizations etc.)

I don’t think I have actually tried this, but I believe you can pass an image to cvMoments() – instead of a blob sequence and then get the centroid with that data.

should be the same as this ( this is from the contour finder in opencv addon)

centroid.x = (int) (myMoments->m10 / myMoments->m00);
centroid.y = (int) (myMoments->m01 / myMoments->m00);

Any idea how to implement that?

You have the centroid info inside the contourFinder:

contourFinder.blobs[i].centroid (return a ofPoint).

how can i know the position of the centroid in relation of the frame ? te position of the centroid here is in relation of de contour…