opencv中Canny操作的高低阈值自动计算 [英] Automatic calculation of low and high thresholds for the Canny operation in opencv

查看:81
本文介绍了opencv中Canny操作的高低阈值自动计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 OpenCV 中,canny 算子的低阈值和高阈值是强制性的:

In OpenCV, the low and high thresholds for the canny operator are mandatory:

cvCanny(input,output,thresh1,thresh2)

在 Matlab 中,有一个选项可以自动计算:

In Matlab, there's an option to calculate those automatically:

edge(input,'canny')

我已经研究了 Matlab 的边缘代码,这对于自动计算这些真的不是很直接.

I've looked into Matlab's code for edge, and this is really not straight forward to calculate those automatically.

您知道 OpenCV 的 Canny 运算符以及自动阈值计算的任何实现吗?

Are you aware of any implementation of the canny operator along with automatic threshold calculation for OpenCV?

推荐答案

我在寻找自动计算 Canny 阈值的方法时偶然发现了这个答案.

I stumbled upon this answer while I was searching for a way to automatically compute Canny's threshold values.

希望这可以帮助那些正在寻找一种确定 Canny 算法的自动阈值的好方法的人......

Hope this helps anyone who comes looking for a good method for determining automatic threshold values for Canny's algorithm...

如果您的图像由不同的前景和背景组成,则可以使用以下方法提取前景对象的边缘:

If your image consists of distinct foreground and background, then the edge of foreground object can use extracted by following:

  1. 使用以下方法计算 Otsu 阈值:

  1. Calculate Otsu's threshold using:

double otsu_thresh_val = cv::threshold(
    orig_img, _img, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU
);

我们不需要_img.我们只对 otsu_thresh_val 感兴趣,但不幸的是,目前 OpenCV 中没有允许您仅计算阈值的方法.

We don't need the _img. We are interested in only the otsu_thresh_val but unfortunately, currently there is no method in OpenCV which allows you to compute only the threshold value.

使用 Otsu 阈值作为较高阈值,与 Canny 算法的较低阈值相同的一半.

Use the Otsu's threshold value as higher threshold and half of the same as the lower threshold for Canny's algorithm.

double high_thresh_val  = otsu_thresh_val,
       lower_thresh_val = otsu_thresh_val * 0.5;
cv::Canny( orig_img, cannyOP, lower_thresh_val, high_thresh_val );

与此相关的更多信息可以在 本文:Otsu 方法在 Canny 算子中的应用研究.可以在此处找到对 Otsu 实施的说明.

More information related to this can be found in this paper: The Study on An Application of Otsu Method in Canny Operator. An explaination of Otsu's implementation can be found here.

这篇关于opencv中Canny操作的高低阈值自动计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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