hi, i have a mask obtained by threshold function. i wonder if i can find its centroid with builtin function, now i'm doing manual:
float sumx=0, sumy=0;
float num_pixel = 0;
for(int x=0; x<difference.cols; x++) {
for(int y=0; y<difference.rows; y++) {
int val = difference.at<uchar>(y,x);
if( val >= 50) {
sumx += x;
sumy += y;
num_pixel++;
}
}
}
Point p(sumx/num_pixel, sumy/num_pixel);
but probabilly is there a better way..