Lane Detection

Finding Lane Lines on the Road


I did this project as a part of the Udacity Self-Driving Car Nanodegree program. It is an implementation in Python 3 to detect lane lines on the road. In this blog post I have described the pipeline to achieve this task. The complete code for the project is available here.

Description of the pipeline


My pipeline consists of 6 steps. For illustration I have used an example image shown below to show the effect of all the operations in my pipeline.

1. Color to grayscale conversion

The color image is converted to grayscale to make the computation easier and to detect lane lines of any color.

2. Gaussian blur

Gaussian blur is applied on the grayscaled image to remove noise and spurious gradients. Gradients are calulated by the change in the intensity of gray value between adjacent pixels. More information about OpenCV’s Gaussian blur can be found here. I used a kernel size of 3 for Gaussian blur since the Canny edge detector (described next) already includes Gaussian smoothing.

3. Canny transform

Canny edge detection is applied to the Gaussian-blurred image. This allows us to detect edges on the basis of change in the gradient intensity and direction at every pixel. The algorithm will first detect strong edge (strong gradient) pixels above the high_threshold, and reject pixels below the low_threshold. Next, pixels with values between the low_threshold and high_threshold will be included as long as they are connected to strong edges. The output edges is a binary image with white pixels tracing out the detected edges and black everywhere else. I used a low_threshold value of 50 and a high_threshold value of 150.

4. Region of interest mask

A mask is drawn to select only the relevant region in which there is a possibility of lane lines being present. This would be generally a quadrilateral shaped region in the bottom half of the image. The mask selects the white colors (edges) from the image obtained after applying Canny transformation using a bitwise and operation.

5. Hough transform

Hough transform is applied on the the image obtained after applying the region of interest mask. The probabilisitc Hough transform is used to construct line segments using the edge points detected in the previous step. More information about using Hough transform can be found here. The edges are segments colored in red. The coordinates of the end points of the line segments are returned by the Hough transform function.

6. Drawing lane lines

The line segments obtained in the previous step are extrapolated to draw straight red colored lines along the lane lines. This is accomplished by modifying the draw_lines() function in the following ways:

Project Video



Potential shortcomings


Possible improvements