Haar Training: error (-215)_img.row * _img.cols == vecSize in function

孤人 提交于 2019-12-23 09:27:55

问题


I am trying to train a Haar Cascade to detect hands. I have a vec file of size 1000. I have 40 positive images and 600 negative images. I have tried both dropping my positive images and negative images. When I run the following command I receive the following error:

opencv_traincascade -data classifier -data classifier -vec samples.vec -bg negatives.txt
-numstages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\ -numNeg 600 -w 80
-h 40 -mode ALL -precalcValBufSize 1024\ -precalcIdxBufSize 1024

PARAMETERS:
cascadeDirName: classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 1000
numNeg: 1000
numStages: 20
precalcValBufSize[Mb] : 256
precalcIdxBufSize[Mb] : 256
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC



===== TRAINING 0-stage =====
<BEGIN
OpenCV Error: Assertion failed (_img.rows * _img.cols == vecSize) in get, file /home/lie/Desktop/Install-OpenCV-master/Ubuntu/2.4/OpenCV/opencv-2.4.9/apps/traincascade/imagestorage.cpp, line 157
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/lie/Desktop/Install-OpenCV-master/Ubuntu/2.4/OpenCV/opencv-2.4.9/apps/traincascade/imagestorage.cpp:157: error: (-215) _img.rows * _img.cols == vecSize in function get

Aborted (core dumped)

I tried lowering my positive count and doing the whole process over again and still received the same error. Any suggestions?

By the way: I am following the tutorial at : http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html

Thank you


回答1:


The error does not seem to be a result of large number of positive or negative samples. People do train very large data sets!

From the parameters described above, it can be noticed that the dimension of the positive samples that form the samples.vec is 24x24, which is denoted by the statement:

sampleWidth: 24
sampleHeight: 24

But while calling the opencv_traincascade function, you try to set the dimension as 80x40. Try changing this to -w 24 -h 24




回答2:


The assertion is quite clear: it expects that _img.rows*_img.cols == vecSize. I dont know what _img and vecSize are supposed to be, but that means that your input data are not correctly given. Just looking at your command line, you:

  1. Wrote -data classifier -data classifier twice. That should not be a problem but still.
  2. Wrote -numPos 1000\ -numNeg 600, while you talk about 40 positive and 600 negative images, so shouldn't you be using those figures instead?

You say you have a vecSize of size 1000. What is this vecSize for again?




回答3:


Lowering numPos and numNeg under the real value, works for me.



来源:https://stackoverflow.com/questions/27726973/haar-training-error-215-img-row-img-cols-vecsize-in-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!