简体   繁体   English

霍夫变换检测较短的线

[英]Hough transform detect shorter lines

Im using opencv hough transform to attempt to detect shapes.我使用 opencv hough 变换来尝试检测形状。 The longer lines are all very nicely detected using the HoughLines method.but the shorter lines are completely ignored.使用 HoughLines 方法可以很好地检测到较长的线条。但较短的线条被完全忽略。 Is there any way to also detect the shorter lines?有没有办法也检测较短的线?

the code I'm using is described on this page http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html我正在使用的代码在这个页面上有描述http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html

I'm more interested in lines such as the corner of the house etc. which parameter should I modify to do this with Hough transform?我对房子的角落等线条更感兴趣。我应该修改哪个参数来使用霍夫变换来做到这一点? or is there a different algorithm I should be looking at或者有没有我应该考虑的不同算法

Hough 变换与 OpenCV python 教程

On the link you provide look at HoughLinesP在您提供的链接上查看HoughLinesP

import cv2
import numpy as np

img = cv2.imread('beach.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
minLineLength = 100
maxLineGap = 5
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 50, minLineLength, maxLineGap)
for x1, y1, x2, y2 in lines[0]:
    cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.imwrite('canny5.jpg', edges)
cv2.imwrite('houghlines5.jpg', img)

Also look at the edge image generated from Canny.另请查看从 Canny 生成的边缘图像。 You should only be able to find lines where lines exist in the edge image.您应该只能找到边缘图像中存在线条的线条。

在此处输入图片说明

and here is the line detection output overlaid on your image:这是覆盖在图像上的线检测输出:在此处输入图片说明

Play around with variables minLineLength and maxLineGap to get a more desirable output.使用变量minLineLengthmaxLineGap来获得更理想的输出。 This method also does not give you the long lines that HoughLines does, but looking at the Canny image, maybe those long lines are not desirable in the first place.这种方法也不会像 HoughLines 那样给你长线,但是看看 Canny 图像,也许那些长线一开始就不受欢迎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM