This version 3.0 was updated on 19-05-2011
(PAN = Pablo Augusto Negri :-) )
This is a real adaboost vehicle detector MATLAB implementation that follows the guidelines of my research paper: "A Cascade of Boosted Generative and Discriminative Classifiers for Vehicle Detection" [1]. The original C++ code as well as the images database belong to Paris 6 University and Peugeot Citroën PSA, which preclude me from sharing them. In order to illustrate my work, I developed a new code that provides the rules for implement my learning method, using Real Adaboost instead of Discret Adaboost.
First at all, you have to obtain two mex files, compiling with MATLAB the files in the ‘Functions\c’ folder: getHaarData_c.c and getHogData_c.c. Then, use the following lines in MATLAB command prompt (assuming that your actual folder is ‘Fonctions\c’):
mex getHaarData_c.c
mex getHogData_c.c
Then, copy the resulting files in 'Functions' folder.
I also included the source files of the library histc_nD_c.dll in 'Functions\c' (This library is part of the Piotr Toolbox: http://vision.ucsd.edu/~pdollar/toolbox/doc/).
If MATLAB says that it can't find histc_nD_c.dll, this file is not compatible with your MATLAB version and you have to compile the library.
Proceed like the others c files. Use, from the MATLAB console,
mex histc_nD_c.c
and copy the resulting file in 'Functions' folder.
The framework is organized in three steps: getData, trainingBoost and detection.
GetData
The folder contains two scripts:
script_get_Haar_index,
script_get_HoG_index and one function
getData.m.
The first two calculate the Haar and HoG features vectors descriptors, necessaries for the following steps.
This new version has four kind of rectangles filters for the Haar vector and three rectangle patchs for the HoG vector. Files results are copied on the others folders.
The function
getData.m extract the features for each positive vehicle sample in the 'Images\Positives' folder and placed them in a matrix saved as 'vehicule_positive_32.mat' on the 'trainBoost' folder. The original images are resized to a 32x32 pixels matrix (the learning pattern).
Training Boost
This is the training algorithm.
To learn the classifier you need to execute the ‘trainCascadeDetector’ function.
The algorithm follows the Real Adaboost implementation procedure given in the Schapire work [2].
The cascade learning is based on Viola [3] rules. I choose the maximum acceptable false positive rate f_max = 40% and the minimum acceptable detection rate per layer d_min=95%. The cascade learning stops either if the overall false positive rate F_target=1e-6 is attainted or if we arrived to the maximum number of layers (equal to 20). Likewise, the learning is interrupted if the number of negative samples founded in the ‘Images\Negatives’ folder is lower than the one of positive samples.
The number in each cascade layer is limited by an exponential law [1].
You have the choice to save the negative feature vectors founded at each adaboost iteration and used for the learning. These samples are extracted randomly from the ‘Images\Negatives’ folder.
The classifier thus generated is saved in the ‘CascadeDetector.mat’ file.
Detection
The final step tests the classifier saved in the 'CascadeDetector.mat' file (there is already a file in the detection folder to test).
Executing the function 'detectionVehicleRealCascade' you will be invited to select a file in the 'Images\Test' folder. Well, there is only one file…
The outcome is the same image with the box detected in red.
Keep in mind that this is a simplified version of the classifier, made it available just to illustrate the method. Moreover, the datasets are not consistent. The positive base use different vehicles datasets downloaded from the web. When using vehicles with a similar appearance for the learning and for the tests, you will (obviously) obtain better results. For the negatives, having a greater image number, you introduce more negative textures in the learning process, thus eliminating easily false positives. Finally, by using more Haar filters and other rectangle patches for the HoG features, you will obtain a more robust detector.
Enjoy it!
Download links (you don't need any password to unzip the files):
code download (170 KB)
images download (45.3 MB)
Please give appropriate acknowledgements when using this code ([1]).
[1] P. Negri, X. Clady, S. M. Hanif, and L. Prevost, "A Cascade of Boosted Generative and Discriminative Classifiers for Vehicle Detection", EURASIP Journal on Advances in Signal Processing, Volume 2008, Article ID 782432, 12 pages.
[2] R. Schapire, Y. Singer, "Improved Boosting Algorithms Using Confidence-rated Predictions", Machine Learning, 37(3):297-336, 1999.
[3] P. Viola, M. Jones, "Real-time Object Detection", International Workshop on Statistical and computational Theories of Vision-Modelling, Learning, Computing and Sampling. Canada, 2001.