The goals/steps of this project are the following:
- Make a pipeline that finds lane lines on the road
- The output should be two solid lines, one for the right side, and the other for the left side
My pipeline consisted of the following steps, and the code is called Lane_line_finding.py
.
I used the following libraries
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import cv2
- Conversion to grayscale using
cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
- Gaussian smoothing using
cv2.GaussianBlur(img, (kernel_size, kernel_size), 0)
- Edge Detection using Canny algorithm, using
cv2.Canny(img, low_threshold, high_threshold)
- Defining the region of interest. This is the area in front of the fixed camera that the lanes appear. I defined an array of four points as the vertices of the polygon, and fill the pixels inside the polygon with a color
cv2.fillPoly
. Then the function returns the image only where the mask pixels are nonzero usingcv2.bitwise_and
. - Finding line segments in the binary image using the probabilistic Hough transform using
cv2.HoughLinesP
. The inputs to this function are the distance and angular resolution in pixels of the Hough grid. Also, the minimum number of votes (intersections in Hough grid cell), the minimum number of pixels making up a line, and the maximum gap in pixels between connectable line segments.- mapping out the full extent of the lane to visualize the result, I defined a function called
draw_lines
. To draw a single line on the left and right lanes, it extrapolates the lines usingnp.polyfit
andnp.poly1d
. The left and right lines are distinguished using their slope. Usually, the slope is about 0.6 or -0.6. Having this number, to avoid small white and yellow marks on the ground affecting the lines, those who have a slope very different than these usual slopes are ignored. Although this is applied to filter the lines before extrapolating, sometimes the extrapolated line may have a slope very different than the usual slope. To avoid reporting wrong lines, the lines after extrapolation are filtered, and those that do not have a usual slope are ignored.
- mapping out the full extent of the lane to visualize the result, I defined a function called
- Combining the original image and the output of the previous step using
cv2.addWeighted
.
Here is the final result, showing the detected lines with the red color:
Image 1 | Image 2 |
---|---|
A video consists of images, so I used the above pipeline and applied it to each image of the video using clip1.fl_image(Lane_Finding_Pipeline_image)
. Not that this is the same pipeline explained above. To do so, I imported the following libraries:
from moviepy.editor import VideoFileClip
from IPython.display import HTML
Video 1 | Video 2 |
---|---|
One potential shortcoming would happen when the line's curvature is large. This is overcome in another project called Advanced Lane Line detection in my github repo.
Another shortcoming could be misled with different signs on the street that are ignored. For example the following lines:
Example 1 | Example 2 |
---|---|
A possible improvement would be to considering higher-order polynomial lines, not only straight lines. Another potential improvement could be to considering different local signs on the ground to avoid being misled with them.
These problems are addressed in the Lane-Line-Detection-using-color-transform-and-gradient in my github repo.
This project is based on the first project of the self-driving car Nanodegree from Udacity.