haar 训练 OpenCV 断言失败 [英] haar training OpenCV assertion failed

查看:18
本文介绍了haar 训练 OpenCV 断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 3340 个正图像和 1224 个负图像在 OpenCV 中为行人训练一个类似于 haar 的分类器.(在 .txt 文件中,我保留负图像名称,即底片(1).bmp,在 txt 文件中,我保留正图像名称,即图片(1).bmp 1 0 0 64 128.实际上正样本已经是行人的裁剪图像,所以我只需要为每张图像指定一个正样本.

I am trying to train a haar-like classifier for pedestrians in OpenCV using 3340 positive images and 1224 negative images. (in a .txt file I keep the negative image names i.e negatives(1).bmp, and in a txt file I keep the positives i.e. 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).

在训练过程中的某个时刻,它会停下来并说:

At some point during the training process it stops and says :

Opencv 错误:未知函数中的断言失败 (elements_read==1),文件 c:pathcvhaartraining.cpp,第 1858 行"

"Opencv Error: Assertion failed (elements_read==1)in unknown function, file c:pathcvhaartraining.cpp, line 1858"

关于造成这种情况的任何想法?

Any ideas as to what is causing this ?

推荐答案

OpenCV DevZone 网站上实用程序的创建者回答了这个问题 2012 年 6 月.

this issue was answered by creater of the utility on the OpenCV DevZone site in June 2012.

引用玛丽亚的话:

问题是您的 vec 文件具有完全相同的样本数您在命令行中传递的 -numPos 979.使用的培训应用程序vec 文件中的所有样本都训练 0-stage 并且它不能得到新的下一阶段训练的正样本,因为 vec 文件已经结束.traincascade 的错误是它在这种情况下有 assert() ,但它必须为用户抛出带有错误消息的异常.它是固定的在 r8913 中.-numPose 是用于训练每个阶段的样本计数.一些已经使用的样本可以被每个前一个阶段过滤(即识别为背景),但不超过 (1 - minHitRate) * numPose在每个阶段.所以 vec 文件必须包含 >= (numPose + (numStages-1)* (1 - minHitRate) * numPose) + S,其中 S 是来自 vec 文件的样本计数,可以立即识别为背景.我希望它可以帮助您创建正确大小的 vec 文件并选择正确的 numPos价值.

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. 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. It was fixed in r8913. -numPose is a samples count that is used to train each stage. 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. 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. I hope it can help you to create vec-file of correct size and chose right numPos value.

它对我有用.我也遇到了同样的问题,我正在关注 著名的 HAAR 培训教程 但想尝试使用更新的培训实用程序-npos 7000 -nneg 2973

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

所以我做了以下计算:

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

vec-file has to contain >= (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

并使用:

-npos 3950 -nneg 2973

-npos 3950 -nneg 2973

它有效.我还注意到其他人在减少 numPos 方面也取得了成功:这里

It works. I also noticed that others have also had success with reducing numPos : here

这篇关于haar 训练 OpenCV 断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆