什么是OpenCV中最基本的线路检测方法

时间:2016-04-03 02:06:22

标签: opencv computer-vision line detection vision

我刚刚学习OpenCV,并对线路检测有疑问。我有一种情况需要检测白色背景上的水平黑线。我保证线条总是水平显示(在几度内)并且需要检测相机图像中的位置。

我的想法是,因为它总是水平的,所以我可以垂直搜索" edge"通过图像上的几列,并称之为好。甚至可能会缩小我从相机捕获的像素数量,作为速度的额外提升。

这种线路检测是否有内置函数?

我不需要额外的电量,也无法承受Canny或Hough的处理时间,我只想尽快找到保证的水平线。

图像(运行我的解决方案)如下所示:

Left is thresholded image, right is solution running. Green bars are horizontal edges, red mark the tape strips I'm interested in tracking.

2 个答案:

答案 0 :(得分:0)

如果您提供所谈论的图像类型,那么建议解决方案会更好。

我也想知道,为什么你不能使用Canny Detector,因为它不是那么昂贵的计算机。您还可以进一步缩小图像,计算边缘并过滤水平边缘。

另一方面,知道水平边缘在图像平面上始终是水平的,您可以使用模板匹配。

答案 1 :(得分:0)

The method I ended up going with is a for loop. After thresholding the image, I search along two columns to find all the "edges" or changes in value. Then I process this list to find only horizontal pairs of edges.

I then find all lines that are close enough together, and have a desired infill (boolean comparison against thresholded image), which effectively only finds the strips of tape I am interested in tracking.

This takes about 1/50th the time of JUST the Canny call, not including the findContours, etc that are also necessary. I have not tested against Hough however, but I believe this will still be significantly faster.

Since the biggest issue was processing speed, I made several other optimizations as well.

Code can be found here (It's very well commented, I promise): Code as a gist