简体   繁体   English

haar培训OpenCV断言失败

[英]haar training OpenCV assertion failed

I am trying to train a haar-like classifier for pedestrians in OpenCV using 3340 positive images and 1224 negative images. 我正在尝试使用3340正面图像和1224个负面图像为OpenCV中的行人训练一个类似于haar的分类器。 (in a .txt file I keep the negative image names ie negatives(1).bmp, and in a txt file I keep the positives ie picture(1).bmp 1 0 0 64 128. Actually positive examples are already cropped images of pedestrians so I only need specify one positive sample per image). (在.txt文件中我保留负图像名称,即负数(1).bmp,并在txt文件中保留正数,即图片(1).bmp 1 0 0 64 128.实际上正面的例子已经是裁剪图像行人所以我只需要为每个图像指定一个正样本。

At some point during the training process it stops and says : 在培训过程中的某个时刻,它停止并说:

"Opencv Error: Assertion failed (elements_read==1)in unknown function, file c:\\path\\cvhaartraining.cpp, line 1858" “Opencv错误:断言失败(elements_read == 1)在未知函数中,文件c:\\ path \\ cvhaartraining.cpp,第1858行”

Any ideas as to what is causing this ? 关于是什么导致这个的任何想法?

this issue was answered by creater of the utility on the OpenCV DevZone site in June 2012. 这个问题在2012年6月由OpenCV DevZone网站上的实用程序创建者回答

To quote Maria: 引用玛丽亚:

The problem is that your vec-file has exactly the same samples count that you passed in command line -numPos 979. Training application used all samples from the vec-file to train 0-stage and it can not get new positive samples for the next stage training because vec-file is over. 问题是你的vec文件与你在命令行-numPos 979中传递的样本数完全相同。训练应用程序使用vec文件中的所有样本训练0阶段,它不能获得新的正样本用于下一个阶段训练因为vec文件结束了。 The bug of traincascade is that it had assert() in such cases, but it has to throw an exception with error message for a user. traincascade的错误在于它在这种情况下有assert(),但它必须为用户抛出一个带有错误消息的异常。 It was fixed in r8913. 它在r8913中修复。 -numPose is a samples count that is used to train each stage. -numPose是用于训练每个阶段的样本计数。 Some already used samples can be filtered by each previous stage (ie recognized as background), but no more than (1 - minHitRate) * numPose on each stage. 一些已经使用的样本可以被每个前一阶段(即被识别为背景)过滤,但每个阶段不超过(1 - minHitRate)* numPose。 So vec-file has to contain >= (numPose + (numStages-1) * (1 - minHitRate) * numPose) + S, where S is a count of samples from vec-file that can be recognized as background right away. 因此vec文件必须包含> =(numPose +(numStages-1)*(1 - minHitRate)* numPose)+ S,其中S是来自vec文件的样本计数,可立即识别为背景。 I hope it can help you to create vec-file of correct size and chose right numPos value. 我希望它可以帮助您创建正确大小的vec文件并选择正确的numPos值。

It worked for me. 它对我有用。 I also had same problem, I was following the famous tutorial on HAAR training but wanted to try the newer training utility with -npos 7000 -nneg 2973 我也有同样的问题,我正在关注HAAR培训着名教程,但想尝试使用-npos 7000 -nneg 2973的新训练实用程序

so i did following calcs: 所以我做了以下计算:

vec-file has to contain >= (numPos + (numStages-1) * (1 - minHitRate) * numPos) + S vec文件必须包含> =(numPos +(numStages-1)*(1 - minHitRate)* numPos)+ S

7000 >= (numPos + (20-1) * (1 - 0.999) * numPos) + 2973 7000> =(numPos +(20-1)*(1 - 0.999)* numPos)+ 2973

(7000 - 2973)/(1 + 19*0.001) >= numPos (7000 - 2973)/(1 + 19 * 0.001)> = numPos

numPos <= 4027/1.019 numPos <= 4027 / 1.019

numPos <= 3951 ~~ 3950 numPos <= 3951 ~~ 3950

and used: 和使用:

-npos 3950 -nneg 2973 -npos 3950 -nneg 2973

It works. 有用。 I also noticed that others have also had success with reducing numPos : here 我也注意到其他人也在减少numPos方面取得了成功: 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM