当我尝试使用 opencv 的 traincascade.exe 时遇到一个问题,我有 20 个正样本和 100 个负样本。也许,它的样本很少,但我只想测试如何使用 opencv 的 traincascade.exe。
我使用 opencv_createsamples.exe 通过命令创建 vector 文件。
D:\Project_Android\Classifier\bin\opencv_createsamples.exe -info positive.txt -vec vector.vec -num 442 -w 24 -h 24 PAUSE
完成了,我有一个 vector.vec,我也有带绝对方向的 negative.txt。
但是现在,当我将 traincascade.exe 与命令一起使用时
D:\Project_Android\Classifier\bin\opencv_traincascade.exe -data HaarTraining -vec vector.vec -bg negative.txt -npos 10 -nneg 10 -numStages 3 -nsplits 2 -nonsym -minhitrate 0.95 -maxfalsealarm 0.4 -mem 1024 -mode ALL -w 24 -h 24 PAUSE
它说错误如下图。
所以我决定用命令将 opencv_traincascade.exe 替换为 opencv_haartraining.exe
D:\Project_Android\Classifier\bin\opencv_haartraining.exe -data HaarTraining -vec vector.vec -bg negative.txt -npos 10 -nneg 10 -numStages 3 -nsplits 2 -nonsym -minhitrate 0.95 -maxfalsealarm 0.4 -mem 1024 -mode ALL -w 24 -h 24 PAUSE
现在它运行了几分钟。
完成后,我在 HaarTraining 文件夹中只看到 8 个文件夹(0,1,2,...),我试图找到 xml 文件但没有看到它,似乎没有生成 xml 文件
所以,请告诉我它有什么问题,我不知道为什么它说 opencv_traincascade.exe 错误并使用 opencv_haartraining.exe 运行但不生成 xml 文件。我确信 positive.txt 和 negative.txt 具有正确的图像绝对方向。
非常感谢你的帮助
最佳答案
首先,不要使用 opencv_haartraining.exe
.它现在已被弃用。
要回答您的问题,您的参数应如下所示:
opencv_traincascade.exe -data HaarTraining -vec vector.vec -bg negative.txt -numPos 10 -numNeg 10 -numStages 3 -minHitRate 0.95 -maxFalseAlarmRate 0.4 -mode ALL -w 24 -h 24
至于你的-mem 1024
, -nsplits 2
, 和 -nonsym
标志,它们不是 opencv_traincascade.exe
使用的实际参数.最接近你的东西-mem
标志可能是 -precalcValBufSize
和 -precalcIdxBufSize
.
有关更全面的参数列表,您可以查看 the official documentation .
关于c++ - 运行 TrainCascade.exe 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37903482/