python - OpenCV HaarCascade 样本不足的可能原因
问题描述
信息
我目前正在尝试训练 HaarCascade 分类器。我达到了训练过程正在发挥作用的地步,并且我能够训练出一个至少“工作”的分类器。这将正确检测很多。现在我试图通过添加更多的正样本和负样本来改善结果。
主意
由于分类器在很多时候都在工作,我决定让它在测试数据集上运行并裁剪出积极分类的图像。这些裁剪的图像是我手动清理的。我现在想将这些新的正面图像添加到我的训练数据集中。
问题
在开始另一次训练运行后,我遇到了以下错误:
POS 当前样本:166 POS 当前样本:167 POS 当前样本:168 POS OpenCV 错误:参数错误(无法获取新的正样本。最可能的原因是给定 vec 文件中的样本数不足。)在 CvCascadeImageReader::PosReader ::get,文件 D:\cv\opencv_3.2.0\sources_withTextModule\apps\traincascade\imagestorage.cpp,第 158 行
到目前为止我尝试了什么
- 我在训练过程中使用Cascade Trainer GUI (3.3.1),所以我检查了日志,如果程序将参数设置为正确的值。特别是计数正图像计数绝对正确。
- 接下来我尝试将我的 minHitRate 降低到 80% 仍然没有运气
- 我过去曾经遇到过这个问题。我通过再次删除添加的正面来解决它,因为它只是一个小批量。这仍然有效,但这次不是一个例外的解决方案。
Cascade Trainer GUI 日志
包括 opencv 调用的所有参数。我还缩短了相对路径以提高可读性。
**************************************************
*************** CREATING SAMPLES *****************
**************************************************
Object : project_name/trainingdata
Fixing file names in negative images folder.
Fixing file names in positive images folder.
Creating negative list project_name/trainingdata/neg.lst
Creating positive list project_name/trainingdata/pos.lst
Running : opencv_createsamples
Info file name: project_name\trainingdata\pos.lst
Img file name: (NULL)
Vec file name: project_name\trainingdata\pos_samples.vec
BG file name: (NULL)
Num: 319
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 24
Height: 24
Max Scale: -1
Create training samples from images collection...
Done. Created 319 samples
**************************************************
************* TRAINING CLASSIFIER ****************
**************************************************
Running : opencv_traincascade
PARAMETERS:
cascadeDirName: project_name\trainingdata\classifier
vecFileName: project_name\trainingdata\pos_samples.vec
bgFileName: project_name\trainingdata\neg.lst
numPos: 319
numNeg: 1000
numStages: 16
precalcValBufSize[Mb] : 4096
precalcIdxBufSize[Mb] : 4096
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
Number of unique features given windowSize [24,24] : 162336
===== TRAINING 0-stage =====
<BEGIN
POS current samples: 1
POS current samples: 2
POS current samples: 3
(...) normal training log produced by opencv (stage0 works without any errors)
(...) then failing at stage1
POS current samples: 167
POS current samples: 168
POS
OpenCV Error: Bad argument (Can not get new positive sample. The most
possible reason is insufficient count of samples in given vec-file.
) in CvCascadeImageReader::PosReader::get, file
D:\cv\opencv_3.2.0\sources_withTextModule\apps\traincascade\imagestorage.cpp, line 158
额外的想法
因为这是我第一次尝试这个,所以我仍然在做很多实验,所以有一些事情可能会出错,但我不太确定,所以我想我可以在这里添加这些内容,以得到知道这些东西的人的确认。
- 我没有调整我的正面或负面的大小。它们中的大多数介于 50x50 到 200x200(正片)和 200x200 到 500x500(负片)之间,这是一个问题吗?我不调整大小,因为在大多数教程中,他们会调整图像大小,并且只在训练后检测到固定大小。我的目标是检测不同大小的物体。
- 我不太明白如何处理 sampleWidth 和 height 以及它们各自的比率。我在想,因为我使用的图像不仅具有 KxK 比率而且还具有 KxJ,这可能会使培训师崩溃。但是在我的原始数据集中(有效)包括这样的比率。
解决方案
- 你必须使用正面而不是负面形象!您的正面图像少于负面图像!
- 为避免此错误,请使用
minHitRate = 0.999
.
推荐阅读
- javascript - 如何切换按钮 onClick 的外观?
- c - 我必须在 GL/glew.h 之后包含 SDL_opengl.h 吗?
- go - GCP IoT 核心拒绝此 RSA_PEM 公钥并出现错误
- node.js - 在 NodeJS 中通过 EJS 和 Express 渲染
- bash - 使用 bash 测试并重新启动服务
- ios - 如何将文件从 Swift 中的 Document/Inbox 移动到内部应用程序,例如“try FileManager.default.moveItem”?
- solr - Solr 返回查询中的所有文档
- node.js - 在 node.js 中使用 dgram 发送 udp 消息
- flutter - 在自定义 TextField 中颤动 Google Places
- java - 按规则排序字符串列表