Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Haar cascade training

Hello,

I want to use a haar cascade classifier to detect objects in a image.

I have 18 positive images and 24 negative images. Their size is 50 x 30. With them, I used this command to generate 1500 samples:

perl bin/createsamples.pl positives.txt negatives.txt samples 1500 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 50 -h 30"

After merging, I started the haar cascade training with this command:

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 50 -h 30 -mode ALL -precalcValBufSize 2048 -precalcIdxBufSize 2048

But it's converging too soon and it hangs in the third state:

PARAMETERS:
cascadeDirName: classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 1000
numNeg: 600
numStages: 20
precalcValBufSize[Mb] : 2048
precalcIdxBufSize[Mb] : 2048
stageType: BOOST
featureType: HAAR
sampleWidth: 50
sampleHeight: 30
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   1000 : 1000
NEG count : acceptanceRatio    600 : 1
Precalculation time: 36
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|0.00333333|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 7 minutes 8 seconds.

===== TRAINING 1-stage =====
<BEGIN
POS count : consumed   1000 : 1000
NEG count : acceptanceRatio    600 : 0.0812568
Precalculation time: 31
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 13 minutes 37 seconds.

I used this link as a reference: http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html.

Does anybody know which parameter can I change to improve the training? Do I need to use more positive or negative images?

Any tip will be very helpful,

Thanks.