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

I am trying to train Haar Cascade to detect hands. I have a vec file of size 1000. I have 40 positive images and 600 negative images. I tried to reset my positive images as well as negative images. When I run the following command, I get 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 

Canceled (kernel resets)

I tried to lower my positive score and repeat the whole process and still got the same error. Any suggestions?

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

thanks

+6
source share
3 answers

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

From the parameters described above, you can notice that the dimension of the positive samples that form sample.vec is 24x24, which is indicated by the expression:

 sampleWidth: 24 sampleHeight: 24 

But when you call the opencv_traincascade function opencv_traincascade you are trying to set the size to 80x40. Try changing this to -w 24 -h 24

+8
source

The statement is quite obvious: he expects _img.rows * _img.cols == vecSize. I don't know what _img and vecSize should be, but that means your input is incorrect. Just by looking at your command line, you:

  • Wrote -data classifier -data classifier twice. This should not be a problem, but still.
  • Wrote -numPos 1000\ -numNeg 600 , while you're talking about 40 positive and 600 negative images, so you shouldn't use these numbers instead?

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

-1
source

Lowering numPos and numNeg to a real value works for me.

-1
source

Source: https://habr.com/ru/post/1210198/


All Articles