Finding Lane Lines on the Road By [email protected]
Finding Lane Lines on the Road
The goals / steps of this project are the following:
- Make a pipeline that finds lane lines on the road
- Reflect on your work in a written report
My pipeline consisted of 5 steps. Most of them were learned in the lesson.
- Color Select
- Grayscale
- Smoothing With Gaussian Blur
- Edge Detect
- ROI Select
- Hough Transform
- Extrapolate line
- Final Videos
I use RGB filtering by applying white and yellow mask on the image. Here are the results:
After color select, I apply grayscaling on the images as shown here:
For good practice, grayscaling images should be smoothing for edge detect. I choose Gaussian Blur to smooth the images.
For edge detect, Canny Alg is a good choice.
After all above steps, I have gotten edge images. Now, I want to remove the unimportant part. The sky, the hill, the tree and others are unimportant. Interest Region is defined by four vertices.
width = image.shape[1]
height = image.shape[0]
v_top_left = [int(width*0.45), int(height*0.6)]
v_top_right = [int(width*0.6), int(height*0.6)]
v_bottom_left = [int(width*0.1), height-2]
v_bottom_right = [int(width*0.95), height-2]
Here is the results after applying it on the Canny images:
I use Hough Transform to detect lines in the images.
After Hough Transform, we get a collection of line segments. How to find left line and right line? I use tuple <slope, intercept>
to indicate a line. If slope is negative, it should be a left line. If slope is positive, it should be a right line.
Through the way, we can get left lines collection and right lines colletion. The weighted average based on intercept length is applied to the two collections to find a left line and a right line.
def average_slope_intercept(lines):
left_lane_lines = [] # (slope, intercept)
left_lane_weights = [] # (length,)
right_lane_lines = [] # (slope, intercept)
right_lane_weights = [] # (length,)
for line in lines:
for x1, y1, x2, y2 in line:
if x2==x1:
continue # ignore a vertical line
slope = (y2-y1)/(x2-x1)
intercept = y1 - slope*x1
length = np.sqrt((y2-y1)**2+(x2-x1)**2)
if slope < 0: # y is reversed in image
left_lane_lines.append((slope, intercept))
left_lane_weights.append((length))
else:
right_lane_lines.append((slope, intercept))
right_lane_weights.append((length))
# Weight slopes and Y_intercepts by their line lenght
right_lane = np.dot(right_lane_weights, right_lane_lines) / np.sum(right_lane_weights) if len(right_lane_weights) > 0 else None
left_lane = np.dot(left_lane_weights, left_lane_lines) / np.sum(left_lane_weights) if len(left_lane_weights) > 0 else None
return right_lane, left_lane
You can find videos from the link:
- Identifying curves.
- The line quality is tested when the car is driving at higher speeds.
- I think there should be a more robust and dynamic method of identifying the road's horizon rather than just including 60% of the image height.
- Polynomial fit for lane line fit