Hi, first time opencv user here trying to retrieve palm lines from images like this:
So far I got rid of the background and concentrated on the palm like this:
// 1. Load img
Mat img = imread(argv[1], CV_LOAD_IMAGE_UNCHANGED);
Size new_size = img.size();
resize(img, img, new_size);
namedWindow("Step 1", CV_WINDOW_AUTOSIZE);
imshow("Step 1", img);
// 2. Grayscale img2
Mat img2;
cvtColor(img, img2, CV_BGR2GRAY);
// 3. Blur 3x3 img2
blur(img2, img2, Size(3, 3));
// 4. Threshold img2
threshold(img2, img2, 125, 255, THRESH_BINARY);
// 5. Find Contours img2
std::vector<std::vector<Point>> contours;
std::vector<Vec4i> hierarchy;
findContours(img2, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
// 6. Get Longest (hand) Contour
auto max_contour = std::max_element(contours.begin(), contours.end(), [](std::vector<Point> const &v1, std::vector<Point> const &v2){
return v1.size()< v2.size();
});
if (max_contour == contours.end())
throw std::runtime_error("No contours found!");
auto max_contour_index = std::distance(contours.begin(), max_contour);
// 7. Draw Contour filled img3
Mat img3(img2.size(), CV_8UC1, Scalar(0));
drawContours(img3, contours, max_contour_index, Scalar(255), CV_FILLED);
// 8. Use img3 as mask to copy img to img3
img.copyTo(img3, img3);
Which gives me this result:
Now I need to extract these palmlines as polygons. However, I'm having trouble coming up with the correct preprocessing and detection algorithms.
I tried
cvtColor(img3, img3, CV_BGR2GRAY);
Mat temp_img;
blur(img3, temp_img, Size(3, 3));
threshold(img3, temp_img, 138, 255, THRESH_BINARY);
Canny(temp_img, temp_img, 150, 150 * 3, 3);
With various parameters using sliders, but it's not giving any results that I can use.
What algorithm can I use to extract these palm lines?