This document describes how to train a classifier for object detection. OpenCV comes already
with a trained classifier for frontal face detection. In order to show that it also works for a variety
of objects, not only for faces, an exemplary training process with bowl is shown. The system used
here is aWi n32 machine with OpenCV beta 3.1 default installation into \u201cC:\Program
The utilities used here should be in<Ope nCV- di r ec t ory >\ bi n. If this is not the case you have to
compile them first by using<Ope nCV- di r ec t or y >\ apps \ Haar Tr ai ni ng\ mak e\f ull .ds w. In all
compilations select the \u201crelease\u201d version as a current configuration in order to avoid creating the
debug version (library and program has \u201cd\u201d appended).
In case some files cannot be found, check the paths of the \u201cinclude files\u201d and \u201clibrary files\u201d in
your development evironment or compile the needed libraries.
In case the steps mentioned above run properly, you should look for any of the missing file(s) in
the OpenCV Yahoo!-Group.
When you try to compile one of the most common problems is that "_cvcommon.h" cannot be
found because it has simply been forgotten in the distribution package. You can download it from
some message attachments of the OpenCV Yahoo!-Group (i.e.
After the orginal code has compiled successfully, you should remove the sample size limitation in
the functionic v Cr e at eI nt Haar Fe at ur es () is to be found in \u201ccvhaartraining.cpp\u201d. Simply replace
s0=36, s1=12, s2=18 and s3=24 with s0=s1=s2=s3=0 and rebuild.
If you are lucky enough to have a multi-processor system or Pentium 4 with \u201cHyper-Threading\u201d for training, you should use the multi-processor feature in cvhaartraining. Thus the haartraining has to be rebuilt with \u201cOpenMP\u201d enabled. Due to the fact that the system used here doesn\u2019t have any of the above mentioned features, we could not experience use of multi-processor features.
You should have a lot of images (about 5,000 to 10,000) as negative (background) samples. You
can get them from well known ressources, i.e. photo-cds (CorelDraw or MS Office) or public
Due to compression artefacts in some compression levels of JPEG images, a BMP image format
should be chosen. The negative (background) resolution used here is equivalent to the one the
video camera uses for later image acquisition (384x256 pixels). But this is not a necessary
\u201cC:\Temp\negatives\\u201d contains the folders of negative images as well as the info files
\u201ctrain.txt\u201d and \u201ctest.txt\u201d.
To work with these images in our utilities, a list of the files is needed. Using Win32 as host OS,
you can get the list via command promt. Move to the folder where the info file will be stored and
type \u201cdir /b /s > infofile.txt\u201d. Open \u201cinfofile.txt\u201d and make the paths relative to the
info file (i.e. find \u201cC:\Temp\negatives\\u201d and replace with \u201c\u201d).
The advantage of object images taken from real world scenes is that you have different
reflections, illuminations and backgrounds. Using IPL the "createsamples" tool can simulate such
conditions but generally they train not that well.
You can get real object images from several sources such as public data sets (as done for face
training) or you can create them by yourself.
The raw images of the bowls were made manually by statues of live video. Several sites with
different floor surfaces and illuminations have been taken to achieve a variety of conditions.
Additionally at each site the camera was positioned in several angles and distances around the
You might want to use "objectmarker.exe" to extract the desired objects out of your raw images,
i.e. taken with a camera [Fig.1-1]. You browse through the folder named \u201crawdata\u201d containing all
BMP format images and mark your object(s) with a bounding rectangle. You can add each
bounding box to the info file \u201cinfo.txt\u201d which you can use for your training and/or testing.
This action might not be possible to undo. Are you sure you want to continue?