【发布时间】:2018-05-22 21:18:51
【问题描述】:
背景:我正在尝试训练自己的 OpenCV Haar 分类器进行人脸检测。我正在使用 Ubuntu 16.04 处理 VM,我的工作目录有 2 个子目录:face 包含 2429 张正片图像,non-face 包含 4548 张负片图像。所有图像均为 png、灰度,宽度和高度均为 19 像素。我生成了一个文件 positives.info,其中包含每个正图像的绝对路径,后跟“1 0 0 18 18”,如下所示:
/home/user/ML-Trainer/face/face1.png 1 0 0 18 18
/home/user/ML-Trainer/face/face2.png 1 0 0 18 18
/home/user/ML-Trainer/face/face3.png 1 0 0 18 18
和另一个文件 negatives.txt,其中包含每个正图像的绝对路径
/home/user/ML-Trainer/non-face/other1.png
/home/user/ML-Trainer/non-face/other2.png
/home/user/ML-Trainer/non-face/other3.png
首先我运行了以下命令:
opencv_createsamples -info positives.info -vec positives.vec -num 2429 -w 19 -h 19
我按预期得到了 positives.vec,然后我创建了一个空目录 data 并运行以下命令:
opencv_traincascade -data data -vec positives.vec -bg negatives.txt -numPos 2429 -numNeg 4548 -numStages 10 -w 19 -h 19 &
似乎运行顺利:
PARAMETERS:
cascadeDirName: data
vecFileName: positives.vec
bgFileName: negatives.txt
numPos: 2429
numNeg: 4548
numStages: 10
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 19
sampleHeight: 19
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
Number of unique features given windowSize [19,19] : 63960
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 2429 : 2429
NEG count : acceptanceRatio 4548 : 1
Precalculation time: 13
+----+---------+---------+
| N | HR | FA |
+----+---------+---------+
| 1| 1| 1|
+----+---------+---------+
| 2| 1| 1|
+----+---------+---------+
| 3| 0.998765| 0.396218|
+----+---------+---------+
END>
Training until now has taken 0 days 0 hours 1 minutes 7 seconds.
然后我收到以下错误:
===== TRAINING 1-stage =====
<BEGIN
POS current samplOpenCV Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
) in get, file /home/user/opencv-3.4.0/apps/traincascade/imagestorage.cpp, line 158
terminate called after throwing an instance of 'cv::Exception'
what(): /home/user/opencv-3.4.0/apps/traincascade/imagestorage.cpp:158: error: (-5) Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
in function get
我该如何解决:
sampleOpenCV 错误:参数错误
任何帮助将不胜感激。
编辑: 我已将 -numPos 修改为较小的数字:2186 (0.9 * 2429),我在阅读this answer 后这样做了,它让我
===== 培训 3 阶段 =====
它给了我同样的错误。我应该如何调整 opencv_createsamples 命令的参数?
【问题讨论】:
-
您必须减少 pos 样本的 nr,因为您会在每个未达到 100% 命中率的阶段丢失一些样本。对于 0.999 的 minHitRate,我通常保留总数的 10% 左右,对于 0.995 的 hR,您可能需要更多。