mrnugget / opencv-haar-classifier-training

Learn how to train your own OpenCV Haar classifier
Other
735 stars 470 forks source link

OpenCV error : Bad Arguement - Can not get new Positive Sample #47

Open reikdas opened 6 years ago

reikdas commented 6 years ago

I had 76 positive images and 3019 negative images. I modified the script on step 5 as -

perl bin/createsamples.pl positives.txt negatives.txt samples 1500\
   "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\
   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 60 -h 80" 

to maintain the ratio as my positive images were of size - 2448 x 3264 pixels. Samples were created successfully.

On running the script python ./tools/mergevec.py -v samples/ -o samples.vec, I got the error as defined in the README - struct.error: unpack requires a string argument of length 12 All but 2 of the files in the samples directory were of size 0 bytes so I deleted them and re-ran the script. It worked fine.

I then ran the script mentioned - opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 60 -h 80 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024 Modifying the height and width parameters again.

This time I get the error -

===== TRAINING 0-stage =====
<BEGIN
OpenCV Error: Bad argument (Can not get new positive sample. Seems that vec-file has incorrect structure.
) in get, file /build/opencv-00QkEr/opencv-2.4.9.1+dfsg1/apps/traincascade/imagestorage.cpp, line 165
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/opencv-00QkEr/opencv-2.4.9.1+dfsg1/apps/traincascade/imagestorage.cpp:165: error: (-5) Can not get new positive sample. Seems that vec-file has incorrect structure.
 in function get

Abortedrent samples: 1