如何在openCV中实现的Canny Edge检测算法中选择最佳参数集? [英] How to select the best set of parameters in Canny Edge detection algorithm implemented in openCV?

查看:1393
本文介绍了如何在openCV中实现的Canny Edge检测算法中选择最佳参数集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android平台上使用openCV。在这个社区和技术人员的大力帮助下,我能够成功地从图像中检测出一张纸。
这些是我使用的步骤。

I am working with openCV on Android platform.With the tremendous help from this community and techies i am able to successfully able to detect a sheet out of the image. These are the step i used.

1.Imgproc.cvtColor()
 2.Imgproc.Canny()
 3.Imgproc.GausianBlur()
 4.Imgproc.findContours()
 5.Imgproc.approxPolyDP()
 6.findLargestRectangle()
 7.find the vertices of the rectangle
 8.find the vertices of the rectangle top-left anticlockwise order using center of mass approach
 9.find the height and width of the rectangle just to maintain the aspect ratio and do warpPerspective transformation.

应用所有这些步骤后,我可以轻松地从图像中获取文档或最大的矩形但这个高度取决于背景和文件表强度的差异。由于Canny边缘的工作原理是强度梯度,因此总是从实施方面假设强度的差异。这就是Canny考虑各种阈值参数的原因。 。

After applying all these steps i can easily get the document or the largest rectangle from an image but this highly depends on the difference in the intensities of the background and the document sheet.As Canny edge works on the principle of intensity gradient ,a difference in intensity is always assumed from the implementation side.That is why Canny took into the account the various threshold parameters.


  1. Lower Thershold

  2. Heigher Thershold

因此,如果像素的强度梯度大于高阈值,它将被添加为输出图像中的边缘像素。如果像素的强度梯度值将被完全拒绝低于阈值。如果像素的强度介于较低和较高阈值之间,则只有当像素连接到任何其他像素值大于高阈值时,才会将其添加为边缘像素。

So if the intensity gradient of a pixel is greater than the Higher Threshold,it will be added as an edge pixel in the output image.A pixel will be rejected completely if its intensity gradient value is lower than the Lower Threshold.And if a pixel have a intensity between the lower and higher threshold ,it will only be added as a edge pixel if it is connected to any other pixel having the value larger than the Higher Threshold.

我的主要目的是使用Canny边缘检测进行文档扫描,因此我想知道如何动态计算这些阈值,以便它可以处理暗背景和浅背景两种情况。

My main purpose is to use Canny edge detection for the document scanning so i want to know how to compute these threshold dynamically so that it can work with the both cases of dark and light background.

我通过手动调整参数尝试了很多,但我找不到与场景关联的关系。

I tried a lot by manually adjusting the parameters , but i couldn't find a relation ship associated with the scenarios.

希望我明白我的观点,并提前致谢

Hope i clear my point ,and Thanks in advance

推荐答案

您可以使用 Otsu的方法

(Python)代码如下所示:

The (Python) Code would look like this:

high_thresh, thresh_im = cv2.threshold(im, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
lowThresh = 0.5*high_thresh

这篇关于如何在openCV中实现的Canny Edge检测算法中选择最佳参数集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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