1
对于我的程序,使用OpenCV和Python,我试图检测道路车道。为了做到这一点,我使用Hough Line Transform来检测线条。然而,它发现许多行彼此相邻,我试图找到一种方法来制作所有这些其他行之间的平均线。提示?Python和OpenCV - 霍夫线变换中的主线
这里是我的代码:
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()
很难将您所指的“每条线旁边的许多条线”图像化,而没有可视化示例。你的意思是阈值未按预期工作? – NAmorim