作者:@阿利同学,邮箱1309399183@qq.com

车道线识别效果

在这里插入图片描述

在这里插入图片描述

车道线识别方法

当我们开车时,我们用眼睛来决定去哪里。道路上显示车道位置的线作为我们将车辆转向的恒定参考。自然,在开发自动驾驶汽车时,我们首先要做的事情之一就是使用算法自动检测车道线。

对于这个项目,一篇优秀的文章应该对项目标准的“反思”部分做出详细的回应。反射有三个部分:
1.描述线条
2.确定任何缺点
3.建议可能的改进
我们鼓励在您的写作中使用图像来演示您的线条提取是如何工作的。
所有这些,请简明扼要!我们不是在找你写一本书:只是一个简短的描述。
视频效果


在这里插入图片描述

主要代码

import math

def grayscale(img):
   
    return cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    # Or use BGR2GRAY if you read an image with cv2.imread()
    # return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
def canny(img, low_threshold, high_threshold):
    """Applies the Canny transform"""
    return cv2.Canny(img, low_threshold, high_threshold)

def gaussian_blur(img, kernel_size):
    """Applies a Gaussian Noise kernel"""
    return cv2.GaussianBlur(img, (kernel_size, kernel_size), 0)

def region_of_interest(img, vertices):
    
    #defining a blank mask to start with
    mask = np.zeros_like(img)   
    
    #defining a 3 channel or 1 channel color to fill the mask with depending on the input image
    if len(img.shape) > 2:
        channel_count = img.shape[2]  # i.e. 3 or 4 depending on your image
        ignore_mask_color = (255,) * channel_count
    else:
        ignore_mask_color = 255
        
    #filling pixels inside the polygon defined by "vertices" with the fill color    
    cv2.fillPoly(mask, vertices, ignore_mask_color)
    
    #returning the image only where mask pixels are nonzero
    masked_image = cv2.bitwise_and(img, mask)
    return masked_image


def draw_lines(img, lines, color=[255, 0, 0], thickness=2):
   
    for line in lines:
        for x1,y1,x2,y2 in line:
            cv2.line(img, (x1, y1), (x2, y2), color, thickness)

def hough_lines(img, rho, theta, threshold, min_line_len, max_line_gap):
    """
    `img` should be the output of a Canny transform.
        
    Returns an image with hough lines drawn.
    """
    lines = cv2.HoughLinesP(img, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap)
    line_img = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8)
    draw_lines(line_img, lines)
    return line_img

# Python 3 has support for cool math symbols.

def weighted_img(img, initial_img, α=0.8, β=1., γ=0.):
   
    return cv2.addWeighted(initial_img, α, img, β, γ)

代码使用流程
步骤1:如果尚未下载安装请安装。
步骤2:打开Jupyter笔记本中的代码
您将在Jupyter笔记本中完成项目代码。如果您不熟悉Jupyter笔记本,请查看Udacity关于Anaconda和Jupyter Notebook的免费课程以开始学习。
Jupyter是一个Ipython笔记本,您可以在其中运行代码块并以交互方式查看结果。这个项目的所有代码都包含在Jupyter笔记本中。要在浏览器中启动Jupyter,请使用终端导航到您的项目目录,然后在终端提示符下运行以下命令(确保您已按照carnd term1 Starter Kit安装说明中的说明激活了Python 3 carnd-term1环境!):
jupyter笔记本
将出现一个浏览器窗口,显示当前目录的内容。单击名为“P1.ipynb”的文件。另一个浏览器窗口将显示笔记本。按照笔记本中的说明完成项目。
步骤3:完成项目并提交Ipython笔记本和项目报告