1 | initial version |
I resolved this problem by using distanceTransform()
int palmCenter(string imageFileName) {
Mat srcImg = imread(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:
2 | No.2 Revision |
I resolved this problem by using distanceTransform()
int palmCenter(string imageFileName) {
Mat srcImg = imread(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;
0; }
}
The result: