OpenCV的C ++中的Canny Edge检测 [英] OpenCV's Canny Edge Detection in C++

查看:246
本文介绍了OpenCV的C ++中的Canny Edge检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提取手的边缘,但我得到以下结果。我试图调整低和高阈值,但我仍然无法获得所需的输出。我已经包括下面的代码及其输出。这是什么问题?

I want to extract the edges of hand but I get the following result. I've tried adjusting the low and high threshold but I still can't get the desired output. I have included below the code and its output. What seems to be the problem?

这是输出

This is the output image generated by the code below.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main(){

    cv::Mat image= cv::imread("open_1a.jpg");
    cv::Mat contours;
    cv::Mat gray_image;

    cvtColor( image, gray_image, CV_RGB2GRAY );

    cv::Canny(image,contours,10,350);

    cv::namedWindow("Image");
    cv::imshow("Image",image);

    cv::namedWindow("Gray");
    cv::imshow("Gray",gray_image);

    cv::namedWindow("Canny");
    cv::imshow("Canny",contours);
    cv::waitKey(0);
}


推荐答案

更改此行

cvtColor( image, gray_image, CV_RGB2GRAY );

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

问题似乎是,你的手在灰度级非常接近灰色背景。我已经应用Canny的颜色(颜色),因为肤色应该有足够的不同。

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.

此外,Canny阈值看起来有点疯狂。接受的规范是,较高的一个应该是2x的3倍的较低。 350是有点太多,它不帮助解决主要问题。

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.

编辑

这些阈值我可以提取很好的轮廓

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

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

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

阅读有关算法的一点理论将帮助您了解发生了什么以及您应该如何改进。 wiki canny 在谷歌

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

但是,上述改进会给你更好的结果10,350. Try(40,120))

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

这篇关于OpenCV的C ++中的Canny Edge检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆