Haar Cascade Classifier Training

1. Prepare training samples (positive/negative)
A. Positive Samples – objectMarker program
• Keep width/height ratio
• Same object with varied background
rawdata/car_0001.bmp 1 24 31 76 57
rawdata/car_0002.bmp 1 15 31 91 66
rawdata/car_0003.bmp 1 35 38 74 56

B. Negative Samples
• Specify unrelated objects: pedestrian detection negative sample: architecture/plaza
• Random generate background samples program (sample size/amount)
• Generate .dat file (.bat)
dir /b > neg_sample.dat

2. Generate sample description files
.vec file for positive samples/.dat for negative samples
CV_createsamples.exe (.bat)
opencv_createsamples -info ./pos/info_car128x128_bmp_100.dat -vec ./pos/info_car128x128_bmp_100.vec -num 50 -w 20 -h 20 -show YES

3. Training with Cascade classifier
A. Train Classifier
CV_haartraining.exe (.bat)
opencv_haartraining -data ./cascade -vec ./pos/info_car128x128_bmp_100.vec -bg ./neg/neg_sample.dat -npos 20 -nneg 60 -mem 200 -mode ALL -w 20 -h 20

B. Combine sub-classifier (.xml file)
convert_cascade --size="20x20" ./cascade haar_adaboost.xml

C. troubleshooting
(1) stuck at one level: run out of negative samples, all remaining negative samples are rejected, random sampling in endless loop
(2) error at one level: same problem as (1). check whether FA value is reasonable to accept present classifier structure.

4. Recognition test – compare with pre-built classifier


Justin DING
one for all, all for one.

Leave a Comment

Your email address will not be published. Required fields are marked *