prateeksawhney97 / Advanced-Lane-Finding-P2

Advanced Lane Detection Project which includes advanced image processing to detect lanes irrespective of the road texture, brightness, contrast, curves etc. Used Image warping and sliding window approach to find and plot the lane lines. Also determined the real curvature of the lane and vehicle position with respect to center.

Home Page:https://www.youtube.com/watch?v=5q50SOwfwAg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Advanced Lane Finding

Udacity - Self-Driving Car NanoDegree

Advanced Lane Detection Project which includes advanced image processing to detect lanes irrespective of the road texture, brightness, contrast, curves etc. Used Image warping and sliding window approach to find and plot the lane lines. Also determined the real curvature of the lane and vehicle position with respect to center.

The Steps involved are:

Computing the camera calibration matrix and distortion coefficients given a set of chessboard images. (9x6)
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") to get a warped image.
Detect lane pixels and fit to find the lane boundary.
Determine the real 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.

Rubric Points

Camera Calibration

1. Briefly state how you computed the camera matrix and distortion coefficients. Provide an example of a distortion corrected calibration image.

The first step in the pipeline is to undistort the camera. Some images of a 9x6 chessboard are given and are distorted. Our task is to find the Chessboard corners an plot them. For this, after loading the images we calibrate the camera. Open CV functions like findChessboardCorners(), drawChessboardCorners() and calibrateCamera() help us do this.

Distortion Corrected Calibrated Image:

input

Some Calibrated Images with points drawn:

output

Pipeline (test images)

1. Provide an example of a distortion-corrected image.

Some examples of Distortion Corrected Images are given below.

The images in the test_images folder serve as our original image. Our task is to Undistort them. For this, I defined a function cal_undistort() which takes in a image and returns the undistorted one using cv2.undistort().

These images are Distortion Corrected :

output_1 output_2 output_3 output_4 output_5 output_6

2. Describe how (and identify where in your code) you used color transforms, gradients or other methods to create a thresholded binary image. Provide an example of a binary image result.

Detecting edges around trees or cars is okay because these lines can be mostly filtered out by applying a mask to the image and essentially cropping out the area outside of the lane lines. It's most important that we reliably detect different colors of lane lines under varying degrees of daylight and shadow. So, that our self driving car does not become blind in extreme daylight hours or under the shadow of a tree.

I performed gradient threshold and color threshold individually and then created a binary combination of these two images to map out where either the color or gradient thresholds were met called the combined_binary in the code.

output_1 output_1 output_2 output_2

3. Describe how (and identify where in your code) you performed a perspective transform and provide an example of a transformed image.

Perspective Transform is the Bird's eye view for Lane images. We want to look at the lanes from the top and have a clear picture about their curves. Implementing Perspective Transform was the most interesting one for me. I used values of src and dst as shown below:

src = np.float32([[590,450],[687,450],[1100,720],[200,720]])

dst = np.float32([[300,0],[900,0],[900,720],[300,720]])

Also, made a function warper(img, src, dst) which takes in the BInary Warped Image and return the perspective transform using cv2.getPerspectiveTransform(src, dst) and cv2.warpPerspective(img, M, img_size, flags=cv2.INTER_NEAREST). The results are shown below:

output_1 output_2 output_3 output_4 output_5 output_6

4. Describe how (and identify where in your code) you identified lane-line pixels and fit their positions with a polynomial?

Once I got the Perspective Transform of the binary warped images, I first used the sliding window method to plot the lane lines and fitted a polynomial using fit_polynomial(img) function. Later on, I used the Search from prior technique and fitted a more accurate polynomial through my perspective transformed images using search_around_poly(image) funtion. Proper markings are there in the code to indicate each and every step.

Finding the lines - Sliding Window and fitting a polynomial

output_1 output_2 output_3 output_4

Finding the lines - Search From Prior and fitting a polynomial

output_1 output_2 output_3 output_4 output_5 output_6

5. Describe how (and identify where in your code) you calculated the radius of curvature of the lane and the position of the vehicle with respect to center.

For calculating the radius of curvature and the position of the vehicle with respect to center, I made a function called radius_and_offset(warped_image) which returns curvature_string and offset. Used left_lane_inds and right_lane_inds for performing the task. Used function fit_poly(image.shape, leftx, lefty, rightx, righty) which returns left_fitx, right_fitx, ploty to calcuate the real radius of curvature and offset.

6. Provide an example image of your result plotted back down onto the road such that the lane area is identified clearly.

After implementing all the steps, it's time to create the pipeline for one image. Created a function process_image() as the main pipeline function. Also, I put the Radius of Curvature and Center Offset on the final image using cv2.putText() function. The result is shown below:

Lane Area Drawn without Information:

output-without-info

Lane Area Drawn with Radius of Curvature and Central Offset:

output-with-radius-and-offset

Pipeline (video)

1. Provide a link to your final video output. Your pipeline should perform reasonably well on the entire project video (wobbly lines are ok but no catastrophic failures that would cause the car to drive off the road!)

Here is the Link to the Project Video

https://www.youtube.com/watch?v=5q50SOwfwAg

Discussion

1. Briefly discuss any problems / issues you faced in your implementation of this project. Where will your pipeline likely fail? What could you do to make it more robust?

The project video ran smoothly. It was successfully drawing the lane area over the road with the radius of curvature and center offset clearly plotted and changing their values. I also ran the Pipeline over the challenge video and the hard-challenge video.

For a standout submission, I followed the suggestion in the lesson to not just search blindly for the lane lines in each frame of video, but rather, once I have a high-confidence detection, using that to inform the search for the position of the lines in subsequent frames of video. For example, if a polynomial fit was found to be robust in the previous frame, then rather than search the entire next frame for the lines, just a window around the previous detection could be searched. This will improve speed and provide a more robust method for rejecting outliers. I performed this step with the help of search_around_poly(image) function.

I think the pipeline will fail when the road curves a lot and there is a sudden change in the direction like the roads in hilly areas as the case in hard-challenge-video. Some measures could be taken so as to adjust the pipeline so that it also draws lane areas over the roads of hilly areas as well i.e. where there are a lot of curves.

About

Advanced Lane Detection Project which includes advanced image processing to detect lanes irrespective of the road texture, brightness, contrast, curves etc. Used Image warping and sliding window approach to find and plot the lane lines. Also determined the real curvature of the lane and vehicle position with respect to center.

https://www.youtube.com/watch?v=5q50SOwfwAg

License:MIT License


Languages

Language:Jupyter Notebook 63.2%Language:HTML 36.8%Language:Shell 0.0%