Loading repository data…
Loading repository data…
akhilesh-k / repository
This repository contains works on a computer vision software pipeline built on top of Python to identify Lanes and vehicles in a video. This project is not part of Udacity SDCND but is based on other free courses and challanges provided by Udacity. It uses Computer vision and Deep Learrning Techniques. Few pipelines have been tried on SeDriCa, IIT Bombay.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
This is not the Repository for the Udacity's Self Driving Car Nanodegree. This is just collection of self sourced Nanodegree projects and resources used are freely available courserwork on Udacity.
Note: The repository does not contain any training images. You have to download and unzip the image datasets of vehicles and non-vehicles provided by Udacity and place them in appropriate directories on your own. I have moved to GTI repository due to small size compared to udacity's. It can be found in training_dataset folder. You can also download it here Please find all the Challanges, Datasets and other Open Sourced Stuffs by Udacity on Self Driving Car here
======= Note: The repository does not contain any training images. You have to download and unzip the image datasets of vehicles and non-vehicles provided by Udacity and place them in appropriate directories on your own. Please find all the Challanges, Datasets and other Open Sourced Stuffs by Udacity on Self Driving Car here
Detect lanes and Vehicles using computer vision and Deep Learning techniques. This project is based on the format and open sourced codes from Udacity Self-Driving Car Nanodegree, and much of the code is leveraged from the provided Jupyter Notebooks.
- Numpy
- cv2
- Matplotlib
- Pickle
- scikit-learn
- scikit-image

The following steps were performed for lane detection:
Following Steps are taken for Vehicle Detection
Run python lanedetect.py. This will take the raw video file at 'project_video.mp4', and create an annotated output video at 'out.mp4'. Afterwards, it will display an example annotated image on screen.
To run the lane detection script for any video files, update the last few lines of 'lanedetect.py'.
Real cameras use curved lenses to form an image, and light rays often bend a little too much or too little at the edges of these lenses. This creates an effect that distorts the edges of images, so that lines or objects appear more or less curved than they actually are. This is called radial distortion, which is the most common type of distortion.
There are three coefficients needed to correct radial distortion: k1, k2, and k3. To correct the appearance of radially distorted points in an image, one can use a correction formula mentioned below.
The camera was calibrated using the chessboard images in camera_calibration/*.jpg. The following steps were performed for each calibration image:
findChessboardCorners() function, assuming a 9x6 boardAfter the above steps were executed for all calibration images, I used OpenCV's calibrateCamera() function to calculate the distortion matrices. Using the distortion matrices, I undistort images using OpenCV's undistort() function.
To illustrate, the following is the calibration image 'camera_cal/calibration5.jpg':
Here is the same image undistored via camera calibration:
The final calibration matrices are saved in the pickle file 'calibrate_camera.p'
The following describes and illustrates the steps involved in the lane detection pipeline. For illustration, below is the original image we will use as an example:
Using the camera calibration matrices in 'calibrate_camera.p', I undistort the input image. Below is the example image above, undistorted:
The code to perform camera calibration is in 'calibrate_camera.py'. For all images in 'test_images/*.jpg', the undistorted version of that image is saved in 'output_images/undistort_*.png'.
The next step is to create a thresholded binary image, taking the undistorted image as input. The goal is to identify pixels that are likely to be part of the lane lines. In particular, I perform the following:
Here is the example image, transformed into a binary image by combining the above thresholded binary filters:
The code to generate the thresholded binary image is in 'combined_thresh.py', in particular the function combined_thresh(). For all images in 'test_images/*.jpg', the thresholded binary version of that image is saved in 'output_images/binary_*.png'.
Given the thresholded binary image, the next step is to perform a perspective transform. The goal is to transform the image such that we get a "bird's eye view" of the lane, which enables us to fit a curved line to the lane lines (e.g. polynomial fit). Another thing this accomplishes is to "crop" an area of the original image that is most likely to have the lane line pixels.
To accomplish the perspective transform, I use OpenCV's getPerspectiveTransform() and warpPerspective() functions. I hard-code the source and destination points for the perspective transform. The source and destination points were visually determined by manual inspection, although an important enhancement would be to algorithmically determine these points.
Here is the example image, after applying perspective transform:
The code to perform perspective transform is in 'perspective_transform.py', in particular the function perspective_transform(). For all images in 'test_images/*.jpg', the warped version of that image (i.e. post-perspective-transform) is saved in 'output_images/warped_*.png'.
Given the warped binary image from the previous step, I now fit a 2nd order polynomial to both left and right lane lines. In particular, I perform the following:
The code to perform the above is in the line_fit() function of 'line_fit.py'.
Since our goal is to find lane lines from a video stream, we can take advantage of the temporal correlation between video frames.
Given the polynomial fit calculated from the previous video frame, one performance enhancement I implemented is to search +/- 100 pixels horizontally from the previously predicted lane lines. Then we simply perform a 2nd order polynomial fit to those pixels found from our quick search. In case we don't find enough pixels, we can return an error (e.g. return None), and the function's caller would ignore the current frame (i.e. keep the lane lines the same) and be sure to perform a full search on the next frame. Overall, this will improve the speed of the lane detector, useful if we were to use this detector in a production self-driving car. The code to perform an abbreviated search is in the tune_fit() function of 'line_fit.py'.
Another enhancement to exploit the temporal correlation is to smooth-out the polynomial fit parameters. The benefit to doing so would be to make the detector more robust to noisy input. I used a simple moving average of the polynomial coefficients (3 values per lane line) for the most recent 5 video frames. The code to perform this smoothing is in the function add_fit() of the class Line in the file 'Line.py'. The Line class was used as a helper for this smoothing function specifically, and Line instances are global objects in 'line_fit.py'.
Below is an illustration of the output of the polynomial fit, for our original example image. For all images in 'test_images/*.jpg', the polynomial-fit-annotated version of that image is saved in 'output_images/polyfit_*.png'.
Given the polynomial fit for the left and right lane lines, I calculated the radius of curvature for each line according to formulas presented here. I also converted the distance units from pixels to meters, assuming 30 meters per 720 pixels in the vertical direction, and 3.7 meters per 700 pixels in the horizontal direction.
Finally, I averaged the radius of curvature for the left and right lane lines, and reported this value in the final video's ann