![](/img/trans.png)
[英]Parallel Line detection using Hough Transform, OpenCV and python
[英]Python and OpenCV - Dominant Line in Hough Line transform
对于我的程序,使用OpenCV和Python,我试图检测道路。 为此,我使用了Hough Line Transform来检测线。 但是,它发现很多行彼此相邻,我正在尝试找到一种方法来使一条平均行介于所有其他行之间。 提示?
这是我的代码:
import numpy as np
import cv2
cap = cv2.VideoCapture('CVfootage.mov')
while(True):
ret, frame = cap.read()
frame = frame[200:720, 0:1280]
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(7,7),0)
edges = cv2.Canny(blur, 50, 150)
lines = cv2.HoughLinesP(image=edges,rho=1,theta=np.pi/180, threshold=100,lines=np.array([]), minLineLength=100,maxLineGap=80)
a,b,c = lines.shape
for i in range(a):
cv2.line(blur, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 3, cv2.LINE_AA)
cv2.imshow('edges', edges)
cv2.imshow('hough', blur)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
您需要调整houghlinesP函数的参数
如果您希望彼此相邻的行较少:增加“ rho”
如果您总体上希望减少行数:增加阈值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.