[英]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.