A Tutorial on Object
Detection Using OpenCV
Introduction
• The goal of object detection is to find an
object of a pre-defined class in a static
image or video frame.
Methods
• Simple objects
Extracting certain image features, such as edges, color
regions, textures, contours, etc.
• Complex objects
Learning-based method:
Viola and Jones, “Rapid object detection using a boosted cascade
of simple features”, CVPR 2001
Statistical model-based training
• Take multiple “positive” samples, i.e., objects of
interest, and “negative” samples, i.e., images
that do not contain objects.
• Different features are extracted from samples
and distinctive features are “compressed” into
the statistical model parameters.
• It is easy to make an adjustment by adding new
positive or negative samples.
Haar-like Features
Example
•Feature’s value is calculated as the difference between the
sum of the pixels within white and black rectangle regions.
1 if f i threshold
f i Sum(ri, white ) Sum(ri, black ) hi ( x)
1 if f i threshold
Adaboost Learning
F sign( w1h1 w2 h2 ... wn hn )
1 if f i i
where, hi ( x)
1 if f i i
The more distinctive the feature, the larger the weight.
Detector in Intel OpenCV
1. Collect a database of positive samples and a
database of negative samples.
2. Mark object by objectmarker.exe
3. Build a vec file out of positive samples using
createsamples.exe
4. Run haartraining.exe to build the classifier.
5. Run performance.exe to evaluate the
classifier.
6. Run haarconv.exe to convert classifier to .xml
file
Links
• Original paper:
http://research.microsoft.com/~viola/Pubs/Detect/violaJones_C
VPR2001.pdf
• How-to build a cascade of boosted classifiers based on Haar-
like features:
http://lab.cntl.kyutech.ac.jp/~kobalab/nishida/opencv/OpenCV_
ObjectDetection_HowTo.pdf
• Objectmarker.exe and haarconv.exe, *.dll:
http://www.iem.pw.edu.pl/~domanskj/haarkit.rar