opencv_traincascade always gets stuck

亡梦爱人 提交于 2019-11-30 09:05:53

问题


I am trying to use OpenCV's opencv_traincascade to generate a Haar Cascade. So far I have 87 distinctive positive samples and 39 negative samples for testing purposes. I generated the .vec file with opencv_createsamples, which worked fine. When I'm running opencv_traincascade it always gets stuck after a few stages, no matter how I change the parameters. My call looks like this:

opencv_traincascade -data /opencvimgs/haarcascades/data/ -vec /opencvimgs/haarcascades/out.vec -bg /opencvimgs/haarcascades/neg.txt -numPos 87 -numNeg 39

I tried increasing and decreasing minHitRate and maxFalseAlarmRate as well as numPos and numNeg without any success. It might run for a few more stages but then it seems to hang in an infine loop again. How can I resolve this?

The output below is what the programm writes to the console:

opencv_traincascade -data /opencvimgs/haarcascades/data/ -vec 
/opencvimgs/haarcascades/out.vec -bg /opencvimgs/haarcascades/neg.txt -numPos 87 -numNeg 39
PARAMETERS:
cascadeDirName: /opencvimgs/haarcascades/data/
vecFileName: /opencvimgs/haarcascades/out.vec
bgFileName: /opencvimgs/haarcascades/neg.txt
numPos: 87
numNeg: 39
numStages: 20
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   87 : 87
NEG count : acceptanceRatio    39 : 1
Precalculation time: 1
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+
END>

===== TRAINING 1-stage =====
<BEGIN
POS count : consumed   87 : 87
NEG count : acceptanceRatio    39 : 0.0697674
Precalculation time: 1
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+
END>

===== TRAINING 2-stage =====
<BEGIN
POS count : consumed   87 : 87
NEG count : acceptanceRatio    39 : 0.00945455
Precalculation time: 1
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+
END>

===== TRAINING 3-stage =====
<BEGIN
POS count : consumed   87 : 87
NEG count : acceptanceRatio    39 : 0.000326907
Precalculation time: 1
+----+---------+---------+
|  N |    HR   |    FA   |
+----+---------+---------+
|   1|        1|        0|
+----+---------+---------+
END>

===== TRAINING 4-stage =====
<BEGIN
POS count : consumed   87 : 87

回答1:


A possible answer is that you're using too few negative samples. Read the instruction from OpenCV documents and reference paper from Viola and Jones. They are using cascaded classifier to achieve high accuracy and low false alarms by eliminate part of the negative samples each time. If you are using too few negative samples, it defeat the purpose of the cascaded classifier in the first place. Notice that, for practical use, the system have much much more images without faces than with faces.



来源:https://stackoverflow.com/questions/14552167/opencv-traincascade-always-gets-stuck

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!