I have joined Udacity to learn Self-Driving Car technology and one of the projects in the first term was vehicle detection using machine learning techniques. That was really interesting project. Check-out my approach to the problem.
The goals / steps of this project are the following:
The code for this step is contained in the 3rd code cell of the IPython notebook.
I started by reading in all the
non-vehicle images. Here is an example of one of each of the
I then explored different color spaces and different
skimage.hog() parameters (
cells_per_block). I grabbed first car image and displayed it to get a feel for what the
skimage.hog() output looks like.
Here is an example using the
YUV color space and HOG parameters of
pixels_per_cell=(8, 8) and
I tried various combinations of parameters and I have decide to make a fair trade-off between car feature recognition and speed of processing it. The problem, which I was was facing was to find best color space for both black and white car. I've decided to use those parameters:
Firstly I had iterate over whole dataset in order to get HOG features from all images. After doing so I have prepared labels for both vehicles and not vehicles images. The dataset and labels were splitted into train and test sets with propotion 8:2 as usually.
LinearSVC classifier was trained with usage of Pipeline and StandardScaler objects. Overall time of training was less than 10s and accuracy was equal 98%.
Training code is contained in 5th cell of the notebook.
In order to implement Window Search, I have implemented function for preparing all windows awailable for the default image size. Windows were created only for the bottom half of the images (without sky), with 50% edge overlapping and with different sizes depending on the vertical position - the more down it goes, the bigger the windows were.
I was checking each window and classifying it in order to know is there a car or not. Because of overlapping character of the windows I was able to generate heatmaps and find spots with high classifications of the cars.
Code for this part is contained in cells 7 and 8 of the notebook.
Ultimately I've decided to use only first channel of the 'YUV' color space, plus spatially binned color and histograms of color in the feature vector, which provided a nice result.
Below you can see how the pipeline performs with test images:
Here's a video with preview.
I recorded the positions of positive detections in each frame of the video. From the positive detections I created a heatmap and then thresholded that map to identify vehicle positions and remove false positives. In order boost correct classification of the cars I have implemented heatmap list for keeping last 20 in memory and use sum of them in order to determine final heatmap. This solution gave me better stability of the vehicle tracking.
I then used
scipy.ndimage.measurements.label() to identify individual blobs in the heatmap. I then assumed each blob corresponded to a vehicle. I constructed bounding boxes to cover the area of each blob detected.
I have decided to implement the solution as it was suggested in the course - using Linear SVM for car classification. It turned out that training was really fast, but in the end classifications were not always true. I think that Deep Learning solution would give much better results.