A simple object detector
with boosting

ICCV 2005 short courses on
Recognizing and Learning Object Categories

Boosting provides a simple framework to develop robust object detection algorithms. This set of functions provide a minimal set to build an object detection algorithm. It is entirely written on Matlab in order to make it easily accesible as a teaching tool. Therefore, it is not appropriate for building real-time applications.


Download the code and datasets
Download the LabelMe toolbox

Unzip both files. Modify the paths in initpath.m
Modify the folder paths in paramaters.m to point to the locations of the images and annotations.

Description of the functions

initpath.m - Initializes the matlab path. You should run this command when you start the Matlab session.
paremeters.m - Contains parameters to configure the classifiers and the database.

Boosting tools
demoGentleBoost.m - simple demo of gentleBoost using stumps on two dimensions

createDatabases.m - creates the training and test database using the LabelMe database.
createDictionary.m - creates a dictionary of filtered patches from the target object.
computeFeatures.m - precomputes the features of all images and stores the feature outputs on the center of the target object and on a sparse set of locations from the background.
trainDetector.m - creates the training and test database using the LabelMe database
runDetector.m - runs the detector on test images

Features and weak detectors
convCrossConv.m - Weak detector: computes template matching with a localized patch in object centered coordinates.

singleScaleBoostedDetector.m - runs the strong classifier on an image at a single scale and outputs bounding boxes and scores.

LabelMe toolbox
LabelMe - Describes the utility functions used to manipulate the database


First run initpath.m and modify the folder paths in the script parameters.m

First run the Boosting demo demoGentleBoost.m

This demo will first ask for a set of points in 2D to be used a training data (Left button = class +1, right button = class -1). The classifier will only be able to perform simple discrimination tasks as it uses stumps as weak classifiers (i.e., only lines parallel to the axis). If you use weak classifiers to be lines with any orientation, then you will get more interesting boundaries easily. However, stumps are frequently used in object detection as they can be used to do efficient feature selection. This demo will show you the limits of stumps. In object detection, some of these limitations are compensated by using a very large number of features.

A look to the database
This is a sample of the images used for this demo. They contain cars (side views) and screens (frontal views), with normalized scale. They are a small subset of the LabelMe dataset. The program createDatabase.m shows how the database used for this demo was created.

If you download the full database, the first thing you have to do is to actualize the folders in parameters.m. Then, you have to run the program createDatabase.m which will read all the annotation files and will create a struct that will be used later by the query tools. For more information about how the query tools work, you can check the LabelMe Toolbox.

Running the detector
Before trying to train your own detector, you can try the script runDetector.m. If everything is setup right, the output should look like:

Here there is an example of the output of the detector when trained to detected side views of cars:

Training a new detector
To train a new detector, first you need to collect a new set of images. If you use the full LabelMe database, then, you will only need to change the object name in the program parameters.m to indicate the object category you want to detect. Also, in parameters.m you can change training parameters such as the number of training images, the size of the patches, the scale of the object, the number of negative examples, etc.

createDictionary.m will create the vocabulary of patches used to compute the features.

computeFeatures.m will precompute all the features for the training images.

trainDetector.m will train the detector using Gentle Boosting [1].

Every one of these programs adds information to the 'data' struct which will contain information such as the precomputed features, list of images used for training, the dictionary of features, the parameters of the classifier.

Finally, with runDetector.m you can run the new detector.

Multiscale detector

In order to build a multiscale detectors, you need to loop on scales. Something like this:
scalingStep = 0.8;
for scale = 1:Nscales
   img = imresize(img, scalingStep, 'bilinear');
   [Score{scale}, boundingBox{scale}, boxScores{scale}] = singleScaleBoostedDetector(img, data);

[1] Friedman, J. H., Hastie, T. and Tibshirani, R., "Additive Logistic Regression: a Statistical View of Boosting." (Aug. 1998)

[2] A. Torralba, K. P. Murphy and W. T. Freeman. (2004). "Sharing features: efficient boosting procedures for multiclass object detection". Proceedings of the 2004 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR). pp 762- 769.