我正在使用opencv_traincascade进行对象检测。我试着在照片上找到眼镜。为此,我已经下载了830张图片,如下所示: http://pi1.lmcdn.ru/product/V/I/VI060DWIHZ27_1_v2.jpg
然后,我已经下载了很多带礼服或连衣裙照片的照片,1799张照片。
然后我用参数启动opencv_traincascade: opencv_traincascade -data特征/分类器-vec samples.vec -bg negatives.txt -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 830 -numNeg 1799 -w 60 -h 90 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024
但是在第4步之后,我有一条消息: 无法填充临时阶段的训练数据集。分支培训终止。
完整的堆栈跟踪是:
➜ pictureFeature opencv_traincascade -data Feature/classifier -vec samples.vec -bg negatives.txt -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 830 -numNeg 1799 -w 60 -h 90 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024
PARAMETERS:
cascadeDirName: Feature/classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 830
numNeg: 1799
numStages: 10
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 60
sampleHeight: 90
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 830 : 830
NEG count : acceptanceRatio 1799 : 1
Precalculation time: 26
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1| 0.145636|
+----+---------+---------+
END>
Training until now has taken 0 days 5 hours 22 minutes 10 seconds.
===== TRAINING 1-stage =====
<BEGIN
POS count : consumed 830 : 830
NEG count : acceptanceRatio 1799 : 0.145715
Precalculation time: 24
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1| 1|
+----+---------+---------+
| 4| 1| 0.762646|
+----+---------+---------+
| 5| 1| 0.432462|
+----+---------+---------+
END>
Training until now has taken 0 days 14 hours 38 minutes 28 seconds.
===== TRAINING 2-stage =====
<BEGIN
POS count : consumed 830 : 830
NEG count : acceptanceRatio 1799 : 0.062696
Precalculation time: 28
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1| 1|
+----+---------+---------+
| 4| 1| 0.590328|
+----+---------+---------+
| 5| 1| 0.187326|
+----+---------+---------+
END>
Training until now has taken 0 days 23 hours 21 minutes 4 seconds.
===== TRAINING 3-stage =====
<BEGIN
POS count : consumed 830 : 830
NEG count : acceptanceRatio 1799 : 0.0117929
Precalculation time: 21
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 1|0.0944969|
+----+---------+---------+
END>
Training until now has taken 1 days 3 hours 47 minutes 34 seconds.
===== TRAINING 4-stage =====
<BEGIN
POS count : consumed 830 : 830
NEG count : acceptanceRatio 1799 : 0.00112161
Precalculation time: 18
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 0|
+----+---------+---------+
END>
Training until now has taken 1 days 5 hours 4 minutes 35 seconds.
===== TRAINING 5-stage =====
<BEGIN
POS count : consumed 830 : 830
Train dataset for temp stage can not be filled. Branch training terminated.
我尝试使用cascade.xml进行对象搜索,但结果完全失败。
有人能解决我的问题吗?
答案 0 :(得分:3)
这是一个非常常见的错误。我对此错误知之甚少,我只能猜测一个解决方案,因为这个错误有很多可能的原因。
它可能与目录结构有关(只需注意负面示例的路径应该相对于当前目录)
或因为bg文件中的换行符(在你的情况下为negatives.txt)是错误编码的。 你可以请仔细检查&negative; .sxt&#39;中每一行的最后一个字符。文件是&#39; \ n&#39;而不是&#39; \ r&#39; ?
同时继续尝试将正负样本比率保持在25%-30%左右
最后确保所有的正面和负面图像都包含头部:
在样本图片(830中的一个)中,只有一个太阳镜可见(没有头,没有听到,没有头发)只有白色背景,所以你的分类器将最终训练,只在白色背景上识别太阳镜,所以当面部可见时,没有机会识别任何太阳镜;
尽量尊重:
正面图片= 带太阳镜的头部
负面图片= 仅限正面
此致
答案 1 :(得分:3)
如果您查看错误,您会发现它已停止在NEG计数&#39;这意味着在第5阶段阅读负面训练数据集图像存在问题。所以你需要修正负面训练样本的路径才能发挥作用。
以下是有关此问题的详细讨论,可能会有所帮助:Cascade Training Error OpenCV 2.4.4
这也可能是bg.txt文件的问题,这是另一个答案:error in train casacde。
另一篇帖子类似error: Train dataset for temp stage can not be filled.
如果无效则尝试使用不同版本的open cv:http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/download