Ask Your Question

Revision history [back]

opencv_traincascade too quick with bad results

Hello, I'm trying to make an app in python which basically counts the amount of money in the picture or camera feed.

I assumed that Haar cascade detection is the right one for this job, so I followed this tutorial: https://pythonprogramming.net/haar-cascade-object-detection-python-opencv-tutorial/

So I downloaded about 2500 negative images showing tables, I took the image he used (50x50): image description, scaled every negative to 100x100 and after execution of these 3 commands:

opencv_createsamples.exe -img .\obverse.jpg -bg .\bg.txt -info .\info\info.lst -pngoutput .\info\ -maxxangle 0.5 -maxyangle 0.5 -maxzangle 0.5 -num 2500

opencv_createsamples.exe -info .\info\info.lst -num 2500 -w 20 -h 10 -vec positives.vec

opencv_traincascade.exe -data .\data\ -vec .\positives.vec -bg .\bg.txt -numPos 2000 -numNeg 1000 -numStages 10 -w 20 -h 10

I seem to be getting good results (didn't actually wait till stage 10, but it generates some good results (seems to me)).

However, after swapping the watch to this image of a polish banknote:

image description,

resizing it from 909x403 to 50x25, resizing negatives to 100x50 and running previous 3 commands, the training lasts 1 minute until stage 8, where it achieves false alarm rate:

opencv_traincascade.exe -data .\data\ -vec .\positives.vec -bg .\bg.txt -numPos 2000 -numNeg 1000 -numStag
es 10 -w 20 -h 10
PARAMETERS:
cascadeDirName: .\data\
vecFileName: .\positives.vec
bgFileName: .\bg.txt
numPos: 2000
numNeg: 1000
numStages: 10
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 20
sampleHeight: 10
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
Number of unique features given windowSize [20,10] : 19865

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   2000 : 2000
NEG count : acceptanceRatio    1000 : 1
Precalculation time: 1.158
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|    0.999|    0.312|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 2 seconds.

===== TRAINING 1-stage =====
<BEGIN
POS count : consumed   2000 : 2002
NEG count : acceptanceRatio    1000 : 0.323311
Precalculation time: 1.197
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|   0.9965|    0.624|
+----+---------+---------+
|   4|   0.9955|    0.397|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 6 seconds.

===== TRAINING 2-stage =====
<BEGIN
POS count : consumed   2000 : 2011
NEG count : acceptanceRatio    1000 : 0.115727
Precalculation time: 1.268
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|        1|    0.741|
+----+---------+---------+
|   4|   0.9995|    0.546|
+----+---------+---------+
|   5|   0.9955|    0.378|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 11 seconds.

===== TRAINING 3-stage =====
<BEGIN
POS count : consumed   2000 : 2020
NEG count : acceptanceRatio    1000 : 0.0514801
Precalculation time: 1.249
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|   0.9995|    0.845|
+----+---------+---------+
|   4|   0.9965|    0.661|
+----+---------+---------+
|   5|    0.996|    0.498|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 15 seconds.

===== TRAINING 4-stage =====
<BEGIN
POS count : consumed   2000 : 2028
NEG count : acceptanceRatio    1000 : 0.0274937
Precalculation time: 1.277
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|   0.9995|    0.794|
+----+---------+---------+
|   3|    0.999|    0.636|
+----+---------+---------+
|   4|    0.996|    0.489|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 20 seconds.

===== TRAINING 5-stage =====
<BEGIN
POS count : consumed   2000 : 2036
NEG count : acceptanceRatio    1000 : 0.013755
Precalculation time: 1.57
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|    0.999|    0.813|
+----+---------+---------+
|   4|        1|    0.835|
+----+---------+---------+
|   5|   0.9975|    0.607|
+----+---------+---------+
|   6|   0.9965|    0.472|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 27 seconds.

===== TRAINING 6-stage =====
<BEGIN
POS count : consumed   2000 : 2044
NEG count : acceptanceRatio    1000 : 0.00734128
Precalculation time: 1.356
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|   0.9955|     0.82|
+----+---------+---------+
|   4|   0.9985|    0.899|
+----+---------+---------+
|   5|   0.9975|    0.825|
+----+---------+---------+
|   6|   0.9975|    0.702|
+----+---------+---------+
|   7|   0.9955|    0.599|
+----+---------+---------+
|   8|   0.9955|    0.455|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 35 seconds.

===== TRAINING 7-stage =====
<BEGIN
POS count : consumed   2000 : 2053
NEG count : acceptanceRatio    1000 : 0.0035139
Precalculation time: 1.19
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|        1|        1|
+----+---------+---------+
|   4|    0.999|    0.891|
+----+---------+---------+
|   5|   0.9965|    0.809|
+----+---------+---------+
|   6|   0.9965|    0.641|
+----+---------+---------+
|   7|   0.9985|    0.637|
+----+---------+---------+
|   8|    0.998|    0.536|
+----+---------+---------+
|   9|    0.998|     0.43|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 45 seconds.

===== TRAINING 8-stage =====
<BEGIN
POS count : consumed   2000 : 2057
NEG count : acceptanceRatio    1000 : 0.00165346
Precalculation time: 1.323
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        1|
+----+---------+---------+
|   2|        1|        1|
+----+---------+---------+
|   3|   0.9975|    0.785|
+----+---------+---------+
|   4|    0.997|    0.797|
+----+---------+---------+
|   5|   0.9955|    0.687|
+----+---------+---------+
|   6|    0.996|    0.636|
+----+---------+---------+
|   7|   0.9955|    0.558|
+----+---------+---------+
|   8|   0.9965|    0.528|
+----+---------+---------+
|   9|   0.9955|    0.399|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 0 minutes 55 seconds.

===== TRAINING 9-stage =====
<BEGIN
POS count : consumed   2000 : 2067
NEG count : acceptanceRatio    0 : 0
Required leaf false alarm rate achieved. Branch training terminated.

I am pretty sure I don't understand the concept of training properly. I'd appreciate any hints :)