从Canny边缘检测中提取线条 [英] extract lines from canny edge detection

查看:898
本文介绍了从Canny边缘检测中提取线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用canny边缘检测后,在openCV中,我想进一步处理结果(仅显示水平线,删除短线等).但是,精明的结果只是另一幅图像.我想得到一系列描述检测到的边缘的线

In openCV after applying canny edge detection I'd like to further process the result (show only horizontal lines, remove short lines, etc..). But the result of canny is just another image. I'd like to get an array of lines describing the detected edges

我知道著名的霍夫线变换,但结果并不总是很好,这就是为什么我想手动处理精简结果. 输入:

I'm aware of the famous Hough Line Transform, but the result is not always good, that's why I'd like to manually process canny result. input:

仅输出canny:

先输出佳能,然后进行霍夫线变换

output canny then Hough line transform

这是用于检测楼梯边缘的霍夫线变换结果(红线).尽管canny edge检测到了边缘,但仍无法正确检测到下面的第4行.

This is Hough line transform result(red lines) for detecting edges of stairs. 4th line from below is not detected correctly, although canny edge detected an edge.

有什么想法要从佳能图像中提取边缘吗?

Any idea how to extract edges from canny image?

推荐答案

可以尝试一些改善结果的方法:

A few things you can try to improve your results:

您的图像看起来具有一些边框窗口效果.我用感兴趣的区域删除了它们,从而得到了一个看起来像这样的图像(我对其进行了调整,直到看起来正确为止,但是如果您使用某种内核运算符,则窗口大小可能会更好地定义此ROI):

Your image looks to have some bordering window effects. I removed them with a region of interest resulting in an image that looks like this (I tweaked it until it looked right, but if you're using some kind of kernel operator it's window size probably better defines this ROI):

似乎您正在使用概率霍夫变换.因此,您只会得到线段,而不是插值线.考虑使用标准变换来获得完整的理论线(rho,theta).这样做,我得到了如下图所示的图像:

It also seems you're using the probabilistic Hough transform. So, you're only getting line segments instead of an interpolated line. Consider using the standard transform to get the full theoretical line (rho, theta). Doing this I got an image like shown below:

这是我用来从Python界面生成行的代码段:

Here is a code snippet I used to generate the lines (from Python interface):

(mu, sigma) = cv2.meanStdDev(stairs8u)
edges = cv2.Canny(stairs8u, mu - sigma, mu + sigma)
lines = cv2.HoughLines(edges, 1, pi / 180, 70)

根据角度过滤线

您可以通过获取最频繁出现的线角并丢弃异常值来过滤掉不良线.这应该将其范围缩小到最明显的步骤.

Filter lines based on angle

You can probably filter out poor lines by taking the most frequently occurring line angles, and throwing away outliers. This should narrow it down to the most visible steps.

希望有帮助!

这篇关于从Canny边缘检测中提取线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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