How to find the center of one palm in the picture

In the below picture, there is on palm, how to find the center point of this palm using OpenCV? It will be very appreciated if anyone can tell me the method.

I want to find the center point of the palm center region, see the below image, I want to find the center of the red circle

when use connectedComponentsWithStats(), I get the centroid point, see the below image, the centroid point(the blue point) is not which I want

edit retag close merge delete

If you want to do it yourself, you could iterate over the image, all the while finding the average location of the white pixels. Or... see LBerger's answer.

( 2017-12-19 09:30:18 -0500 )edit

Try finding the maximum inscribed circle or have a look at the distance transform.

( 2017-12-20 07:18:05 -0500 )edit
1

You can erode the object a few times to get rid of the fingers. Then get the centroid using the connectedComponentsWithStats or the Hu moments.

( 2017-12-20 07:22:23 -0500 )edit

If it's hard to erode, you may use region growth with left-up-right three directions, starting from the white pixel which has the largest y-value, as a result, you'll get the palm and a finger, shaping like a lollipop. Finally, count the horizontal length for each row to eliminate the finger.

( 2017-12-21 05:27:51 -0500 )edit

Sort by ยป oldest newest most voted

I resolved this problem by using distanceTransform()

int palmCenter(string imageFileName) {
if (srcImg.empty()) {
cout << "Filed to open the image " << imageFileName << endl;
return -1;
}

Mat binaryImg;
cvtColor(srcImg, binaryImg, COLOR_BGR2GRAY);
threshold(binaryImg, binaryImg, 200, 255, THRESH_BINARY);
Mat distance;
distanceTransform(binaryImg, distance, DIST_L2, 5, CV_32F);

float maxDist = 0;
int x, y;
for (int i = 0; i < distance.rows; i++) {
for (int j = 0; j < distance.cols; j++) {
float dist = distance.at<float>(i, j);
if (maxDist < dist) {
x = j; y = i;
maxDist = dist;
}
}
}

circle(srcImg, Point(x, y), 3, Scalar(255, 0, 255), 2, 8, 0);
imshow("palmCenter", srcImg);
waitKey(0);
return 0;  }


The result:

more

Use conectedComponentsWithStats and you will get palm centroid

more

I used connectedComponentsWithStats() to get the centroid, but, I found it is the center point of the whole palm, which is not what I want. I want to find the center point of the palm center region, which does not include the finger region

( 2017-12-20 04:15:56 -0500 )edit

It's a better to ask a new question because centroid was a good answer to your previous question. Use edit button to reverse to your previous questions and ask a new one : there is no problem

( 2017-12-20 04:38:49 -0500 )edit