c++ - haar 训练 OpenCV 断言失败

标签 c++ image-processing opencv computer-vision haar-wavelet

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

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

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

关于造成这种情况的原因有什么想法吗?

最佳答案

此问题已由 OpenCV DevZone 网站上的实用程序创建者回答in June 2012.

引用玛丽亚的话:

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.

它对我有用。我也有同样的问题,我正在关注 famous tutorial on HAAR training但想尝试使用更新的培训实用程序 -npos 7000 -nneg 2973

所以我做了以下计算:

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

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

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

numPos <= 4027/1.019

numPos <= 3951 ~~ 3950

并使用:

-npos 3950 -nneg 2973

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

关于c++ - haar 训练 OpenCV 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10863560/

相关文章:

python-3.x - Python 中的 3D Dicom 可视化

php imagecolorat 返回 0。为什么?

c++ - cvShowImage 错误

c++ - 应用程序突然关闭时堆内存清理

c++ - 在编译时检测 C++ 中的函数

image - 如何在 css 中更改图像(图标)的颜色

java - Java 中的 OpenCV Mat 中如何表示二元 vector ?

c++ - 只改变成员的子类是有效的做法吗?

c++ - 不同的函数使用相同的函数,减少开销

python - 使用 fitEllipse 对图像进行椭圆拟合