python+opencv车道线检测(简易实现),供大家参考,具体内容如下
技术栈:python+opencv
实现思路:
1、canny边缘检测获取图中的边缘信息;
2、霍夫变换寻找图中直线;
3、绘制梯形感兴趣区域获得车前范围;
4、得到并绘制车道线;
效果展示:
代码实现:
import cv2
import numpy as np
def canny():
gray = cv2.cvtColor(lane_image, cv2.COLOR_RGB2GRAY)
#高斯滤波
blur = cv2.GaussianBlur(gray, (5, 5), 0)
#边缘检测
canny_img = cv2.Canny(blur, 50, 150)
return canny_img
def region_of_interest(r_image):
h = r_image.shape[0]
w = r_image.shape[1]
# 这个区域不稳定,需要根据图片更换
poly = np.array([
[(100, h), (500, h), (290, 180), (25