user2538255
user2538255

Reputation: 313

bad_alloc() error while haar cascade training

we have been stuck on a problem on haar cascade training for a week now. Actually we are following this tutorial http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html for creating cascade xml file. But on the last command

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt
-numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 45
-numNeg 45 -w 90 -h 100 -mode ALL -precalcValBufSize 1024
-precalcIdxBufSize 1024

we get an error:

terminate called after throwing an instance of 'std::bad_alloc'
what(): std:: bad_alloc
Aborted (core dumped)

Specifications for the images are: 45 positive and 45 negative images(both with dimensions 90 X 100). I have made sure that samples.vec exists in the same folder and have also tried using 2048 for precalcValBufSize parameters. Please help us!

Upvotes: 1

Views: 2019

Answers (1)

Dima
Dima

Reputation: 39389

You've run out of memory. You have several options:

  • Use a 64-bit computer with more memory
  • Use smaller-size positive training images. 24x24 or 32x32 is typical. 64x64 is considered large.
  • Use LBP or HOG features instead of Haar. Haar features take orders of magnitude more memory than the others.

By the way, your negative images should not be the same size as your positive images. Negative images should be large scenes containing backgrounds typically associated with your objects of interest. opencv_traincascade automatically scans them for useful negative samples.

Upvotes: 5

Related Questions