README
Vehicle Detection Project
The goals / steps of this project are the following:
- Perform a Histogram of Oriented Gradients (HOG) feature extraction, binned color features extraction, and histograms of color feature extraction on a labeled training set of images and train a classifier Linear SVM classifier
- Implement a sliding-window technique and use your trained classifier to search for vehicles in images.
- Run your pipeline on a video stream and create a heat map of recurring detections frame by frame to reject outliers and follow detected vehicles.
- Estimate a bounding box for vehicles detected.
Data
The data needed for this project can be found here at these links to the labeled data vehicle and non-vehicle examples that is needed to train the classifier. Extract the contents of the zip files into a folder called "data" in the root of the project directory.
Histogram of Oriented Gradients (HOG)
HOG features extraction and choice of parameters.
First I loaded in the all of the image paths to both the "car" and "non-car" classes. Then in the project when we consider the HOG feature vector we first conver an image from a RGB colour space to a YUV colour space. Next we partition our images such that each block consists of a 2x2 cells, each cell consists of 16x16 pixels. Then we have 11 diferent orientations for the histograms. I choose theses parameters after I tried different parameters on random samples images from each of the two classes and displayed them to get a feel for what output look the 'best'. The code for this step is contained in the "Gradient feature selection (HOG)" and the "HOG Visualization" code cells of the IPython notebook.
Here is an example of the original YUV image and the HOG image produced by this stage of the pipline applied to each of the vehicle
and non-vehicle
classes:
Training the classifier.
I trained a linear SVM by first building a feature vector for each image in both of the "car" and "non-car" classes. Then I randomly shuffle the data into a training set and a testing set with a 80%-20% split. The testing accuracy of the classifier was 99.46%. The classifier could be improved by training on a lager data set that includes motorcycles and semi-trucks as well as using a combination of classifiers, something like adaboosting the SVM's. The code for this step is contained in the "SVM" code cell of the IPython notebook.
Sliding Window Search
For this I would crop roughly the bottom half of the image since there are no flying cars(yet). Then I would compute the HOG of this whole region and then sub-sample from it to avoid having to recompute. I could not decide on a single scale so did the search at 6 different scales, .85, 1.0, 1.25, 1.5, 1.75, 2.0. Each of I would crop the image indifferent sizes as to not make the pipline super slow. The code for this step is contained in the "Sliding Window Test", "Enhanced Sliding Window", and the "Sliding Window With Heat" code cells of the IPython notebook. Here is some example of the sliding window search at multiple scales and the merging of the found bounding boxes
Video Implementation
Here is a link to a youtube video of my pipline in action
Here's a link to my video file
Filter false positives and combining overlapping bounding boxes.
I would generate a heat map of detected positions on the image and would add heat to them. The idea being we can eliminate false positives by only considering positions that are hot enough, that is we thresholded the heatmap to identify vehicle positions. I then assumed each blob corresponded to a vehicle. I constructed bounding boxes to cover the area of each blob detected. We also let the heat decay over time to add a smoothing effect for future frames. Here are some examples of the heat map in action
Discussion
There were not real issues faced in this project other then the slow time to process the large video file.
The pipline could be made more robust by keeping track of the number of cars on screen. Since currenly now when two car are close there bounding boxes merge togeather into one. If we could keep two seperate bounding boxes that would be a great improvement. The pipline is likelly to fail in urban environment where there is a large density of cars on screen, was it would probably draw one large bounding box. The pipline also does not work if there are motorcycles or semi-trucks on the road.