Canny Edge的自适应参数 [英] Adaptive parameter for Canny Edge
问题描述
我正在使用一个使用OpenCV的项目来检测一张卡片,这张卡片会放在一个可折叠的地方。
我已经成功地使用Canny Edge检测它了。但是,对于不同的图像,必须手动调整参数。我希望我的项目可以处理每个图像,而无需手动调整参数。我应该怎么办?
I'm using a project using OpenCV for detecting a card that will be place on a atable. I have successfully detect it using Canny Edge. However, for different image the parameter must be tuned manually. I wish for my project to be worked with every image without manually tune the parameter. What Should I do?
推荐答案
如果您的图像包含不同的背景&前台,您可以自动获取阈值,如下所述: http: //www.academypublisher.com/proc/isip09/papers/isip09p109.pdf 。
If your image consist of Distinct Background & Foreground, You can get the threshold for that automatically as follows explained in this paper http://www.academypublisher.com/proc/isip09/papers/isip09p109.pdf.
- 计算Otsu的阈值+二进制阈值
-
使用Otsu的阈值作为Canny算法的较高阈值。
- Compute Otsu's threshold + Binary threshold for your image.
Use the Otsu's threshold value as higher threshold for Canny's algorithm.
Mat mCanny_Gray,mThres_Gray;
Mat mCanny_Gray,mThres_Gray;
Mat mSrc_Gray = imread(Test.bmp,0);
Mat mSrc_Gray=imread("Test.bmp",0);
double CannyAccThresh = threshold(mSrc_Gray ,mThres_Gray,0,255,CV_THRESH_BINARY | CV_THRESH_OTSU);
double CannyAccThresh = threshold(mSrc_Gray,mThres_Gray,0,255,CV_THRESH_BINARY|CV_THRESH_OTSU);
double CannyThresh = 0.1 * CannyAccThresh;
double CannyThresh = 0.1 * CannyAccThresh;
Canny(mSrc_Gray ,mCanny_Gray,CannyThresh,CannyAccThresh);
imshow(mCanny_Gray,mCanny_Gray);
Canny(mSrc_Gray,mCanny_Gray,CannyThresh,CannyAccThresh); imshow("mCanny_Gray",mCanny_Gray);
您还可以参考此主题。
这篇关于Canny Edge的自适应参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!