OpenCV's Canny Edge Detection in C++

泪湿孤枕 提交于 2019-11-27 13:21:23

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) )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!