OpenCV’s Canny Edge Detection in C++

Change this line

cvtColor( image, gray_image, CV_RGB2GRAY );

to

std::vector<cv::Mat> channels;
cv::Mat hsv;
cv::cvtColor( image, hsv, CV_RGB2HSV );
cv::split(hsv, channels);
gray_image = channels[0];

The problem seems to be that your hand in gray scale is very close to the gray background. I have applied Canny on the hue (color) because the skin color should be sufficiently different.

Also, the Canny thresholds look a bit crazy. The accepted norm is that the higher one should be 2x to 3x the lower. 350 is a bit too much and it doesn’t help solve the main problem.

Edit

with these thresholds I was able to extract quite a good contour

cv::Canny(image,contours,35,90);

Reading a bit of theory about the algorithm will help you understand what happens and what you should do to improve. wiki canny on google

However, the improvement above will give you much better results (provided you use better thresholds than 10, 350. Try (40, 120) )

Leave a Comment