我必须使用Python和OpenCV执行通道检测。 我的代码是:
import numpy as np
import cv2
import math
image=cv2.imread('road.jpg')
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,200)
while True:
lines= cv2.HoughLines(edges, 1, math.pi/180.0, 100, np.array([]), 0, 0)
a,b,c = lines.shape
for i in range(a):
rho = lines[i][0][0]
theta = lines[i][0][1]
a = math.cos(theta)
b = math.sin(theta)
x0, y0 = a*rho, b*rho
pt1 = ( int(x0+1000*(-b)), int(y0+1000*(a)) )
pt2 = ( int(x0-1000*(-b)), int(y0-1000*(a)) )
cv2.line(image, pt1, pt2, (0, 0, 255), 2, cv2.LINE_AA)
cv2.imshow(" road ",image)
if cv2.waitKey(33) == 27:
break
这些是输入和输出:
输入:
输出:
我需要改进houghlines检测,以便只找到与泳道对应的线条。我该怎么办?