The main goal of the project is to create a software pipeline to identify vehicles in a video from a front-facing camera on a car. It is implemented as an image classifier which scans an input image with a sliding window. A linear SVM was used as a classifier for HOG, binned color and color histogram features, extracted from the input image. The classifier is described here.
Feature extraction
To address the task three types of features were used: HOG (Histogram of Oriented Gradients) (shape features), binned color (color and shape features) and color histogram features (color only features). This combination of features can provide enough information for image classification.
It is possible to use built-in functions from different libraries for features extraction.
HOG is implemented in skimage. All that you need is to provide parameters. A detailed description of what is the HOG features available here. It can be used as follows:
The function is very powerful and can even produce the HOG features images just by setting visualise = True and adding an extra output. Here it is an example:
Binned color features is just a downscaled image. Scaling can be done with the OpenCV function resize:
Color histogram features can be computed with the NumPy histogram function. One may use one channel grayscale image or use all colors stacked:
Classifier
Data loading
First of all, we need to load the data.
Hyperparameters
We are going to use the linear SVM classifier from sklearn. It can work with default parameters (but they may be fine-tuned later). There are a lot of hyperparameters of the feature extraction process. So, one may consider using automated way of the parameters tuning.
The extract_features function extract features from the provided list of images with desired parameters.
The hyperparameters may be fine tuned manually as well, for instance, to decrease the feature vector length and, consequently, increase the speed of classification. Final settings:
Test the classifier
(‘Feature vector length:’, 2432)
(13.97, ‘Seconds to train the SVC…‘)
(‘Test Accuracy of the SVC = ‘, 0.9873)
As a result, 98.7% accuracy was obtained.
For details of the implementation see the project repo.