霍夫变换
lines = cv2.HoughLinesP(edge_img,1,np.pi/180,15,minLineLength=40,maxLineGap=20)
?
import cv2
import numpy as np
masked_edge_img.jpg (经过掩码后的图像)
edge_img = cv2.imread('masked_edge_img.jpg',cv2.IMREAD_GRAYSCALE)
mask = np.zeros_like(edge_img)
#获取所有线段
lines = cv2.HoughLinesP(edge_img, 1, np.pi/180, 15, minLineLength=40, maxLineGap=20)
len(lines)
?输出结果 :147 (共有147条线段)
#按照斜率分成车道线
left_lines = [line for line in lines if calculate_slope(line)>0]
right_lines = [line for line in lines if calculate_slope(line)<0]