OpenCV HaarCascade样本不足的可能原因

时间:2018-12-12 16:18:47

标签: python opencv haar-classifier

信息

我目前正在尝试训练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比率,这可能会使训练员崩溃。但是在我的原始数据集(有效的)中包含了这样的比率。

0 个答案:

没有答案