This project goal is to write a software pipeline to identify the lane boundaries in a video. This document will describe the algorithm in details.
The key steps of this project are the following:
- Compute the camera calibration matrix and distortion coefficients given a set of chessboard images.
- Apply a distortion correction to raw images.
- Use color transforms, gradients, etc., to create a thresholded binary image.
- Apply a perspective transform to rectify binary image ("birds-eye view").
- Detect lane pixels and fit to find the lane boundary.
- Determine the curvature of the lane and vehicle position with respect to center.
- Warp the detected lane boundaries back onto the original image.
- Output visual display of the lane boundaries and numerical estimation of lane curvature and vehicle position.
I performed camera calibration using the single image and got camera calibration matrix:
Camera calibration matrix: [[ 872.5223319 0. 649.38554509]
[ 0. 853.10470045 213.74930061]
[ 0. 0. 1. ]]
Original images:
Undistorted images:
The difference is not so big but it can be noticable further if not performed right now.
To get perspective matrix I performed the following calculations:
srcPoints = np.float32(
[[w * 0.18, h * 0.95],
[w * 0.457, h * 0.63],
[w * 0.543, h * 0.63],
[w * 0.82, h * 0.95]])
dstPoints = np.float32(
[[w * 0.25, h],
[w * 0.25, 0],
[w * 0.75, 0],
[w * 0.75, h]])
M = cv2.getPerspectiveTransform(srcPoints, dstPoints)
Minv = cv2.getPerspectiveTransform(dstPoints, srcPoints)
and checked the result using straight image:
vertical lines on the first image shows that perspective matrix is correct.
Next steps are performed for every frame in the video.
Warping is performed using M matrix. The result is displayed on previous image.
After many experiments I found the following binarization algorithm is the best:
- Convert image to HLS color space
- Get L and S channels:
- Adjust gamma on L channel:
- Sum gamma(L) with S images using Max function (i.e. get the brightest pixel from two):
- Do binary thresholding using values min=110, max=255:
Perform lines detection using provided in the lesson algorithm:
Draw the polygon on warped clear image
Unwarp the image using inverted M matrix