The goals 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 will explain step by step the processing of each frame in the video. The numbering of the following sections corresponds to the numbering in Advanced_Lane_Finding.ipynb
notebook. I show results over this original image:
I start by preparing "object points", which will be the (x, y, z) coordinates of the chessboard corners in the world. Here I am assuming the chessboard is fixed on the (x, y) plane at z=0, such that the object points are the same for each calibration image. Thus, objp
is just a replicated array of coordinates, and objpoints
will be appended with a copy of it every time I successfully detect all chessboard corners in a test image. imgpoints
will be appended with the (x, y) pixel position of each of the corners in the image plane with each successful chessboard detection.
I then used the output objpoints
and imgpoints
to compute the camera calibration and distortion coefficients using the cv2.calibrateCamera()
function. I applied this distortion correction to the test image using the cv2.undistort()
function and obtained this result:
I used a combination of color and gradient thresholds to generate a binary image. I particularly combined:
- Gaussian Blur
- S channel of HSV (with with thresholds)
- Maasked yellow color in RGB (with with thresholds)
- Masked white color in RGB (with with threshold)
- Sobel gradient in x,y, magitude and direction.
Here's an example of my output for this step:
I use region_of_interest
to create and crop image in the zone of the line. The result is the following:
The code for my perspective transform includes a function called warper()
. The warper()
function takes as inputs an image (img
), as well as source (src
) and destination (dst
) points. The following image shows the transformation that assigns each blue points to each vertex of the red rectangle:
I verified that my perspective transform was working as expected by drawing the src
and dst
points onto a test image and its warped counterpart to verify that the lines appear parallel in the warped image.
A piece of the video showing the output at this stage:
Once I have the transformed image I used sliding windows method to find lines. The line is searched at the bottom and then the image is traversed upwards by moving a "window" and looking for the continuation of the line in that region. This is the result:
Once I found the lines I use previous line information to search around this region. Results are the following:
If the lines are lost for more than MAX_CORRUPTED_FRAMES
frames, I come back to the Sliding Windows method again. To detect loss of lines, compare previous radius and offset with with new ones.
The radius of curvature of each line are calculated using the following formula (given by Udacity).
Then both radius are averaged and printed on each frame.
To calculate offset, I evaluated the polynomial of each line at the bottom of the image and took the average of both. Then I got the difference between that point and the midpoint of the frame. This result is the offset.
The following parameters are used to transform measurements from pixels to meters:
- ym_per_pix = 30/720 # meters per pixel in y dimension
- xm_per_pix = 3.7/700 # meters per pixel in x dimension
I implemented get rectangle
to print a rectangle between lines. Then I used the inverse transform matrix to get back to the original perspective.
The results of processing the video through the pipeline are shown in the next gif:
I would like to mention some problems of using this pipeline:
- At one point in the video the image has low contrast and the lines are lost. Maybe it could be improved by applying some technique to improve the contrast in those frames.
- The bend radius measurement appears to fluctuate very fast. This can make a true line in a frame appear false compared to the previous frame.