Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Another alternative. This one, just a little upgrade to @berak 's answer - using closing and opening morphological operations after the blur, you can get one final and single contour:

Mat image = imread("hand.jpg", 0);
blur(image, image, Size(8, 8));
image = image > 30;
morphologyEx(image, image, MORPH_CLOSE, Mat(25, 2, CV_8U));
morphologyEx(image, image, MORPH_OPEN, Mat(10, 10, CV_8U));

vector<vector<Point>> contours;
findContours(image, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Mat image_contour(image.rows, image.cols, CV_8UC1, Scalar(0));
drawContours(image_contour, contours, 0, Scalar(255));

And so we get this (image on the left, image_contour on the right):

image descriptionimage description