-1

I used typical haar-cascade of OpenCV. And setup stages as 5 in training process,but in xml & cascade folder only 3 stages were found.

Why I got fewer stages than expected? Any solutions?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Lei Li
  • 21
  • 1
  • 5
  • How much training data did you provide? I've had the training process finish early when using only a small amount of data. – user3510227 Apr 07 '15 at 07:14
  • I used 20 pos with size of 64*64,and 60 neg,with big size,like 400*400, for first try. – Lei Li Apr 07 '15 at 07:22

2 Answers2

0

Take this example training command:

opencv_traincascade -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

This has a maxFalseAlarmRate of 0.5, when the classifier reaches this value it will finish.

For your problem, I imagine you have set the numStages to 5 but after 3 stages it has reached the maxFalseAlarmRate and completed the training.

In order to confirm/dispell this you would need to provide:

  1. Your training command (as above)
  2. The output from your last training stage.
GPPK
  • 6,546
  • 4
  • 32
  • 57
  • thanks. My cmd is : opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\ -numStages 5 -numPos 20\ -numNeg 60 -w 64 -h 64 – Lei Li Apr 07 '15 at 07:31
  • I didn't save the output of last stage. I am trying to use 126 pos and 405 neg with 8 stages,after i get the result.I 'll paste here.thanks – Lei Li Apr 07 '15 at 07:33
  • BTW,Could u please offer some hints for parameters? Such as, how to adapt these parameters regarding to different samples numbers? – Lei Li Apr 07 '15 at 07:36
  • I would suggest following the above example (excluding the precalc values) and alter it with your numPos/numNeg & a alarm rate of 0.8. – GPPK Apr 07 '15 at 07:56
  • U r right. I setup stages as 8,but got 7 stages.It says Required leaf false alarm rate achieved.Branch training terminated . So i need to change maxFalseAlarmRate to smaller values,right? – Lei Li Apr 07 '15 at 09:33
  • if it has achieved the false alarm rate that is good, it has met the goals you have set. If your classifier isn't good enough set it to a higher value (e.g. 0.8) – GPPK Apr 07 '15 at 09:47
0

You most likely have not provided traincascade enough information to learn from. This is most likely because we humans are incredibly lazy and hate to work. It would have kept going if it thought it could learn more from the data you specified.

Take more positives. Remember that you can take multiple images of your object a slightly tilted angles (10º-20º or so). And be sure to provide at least hundreds of your objects, especially if there is quite a bit of variation between your objects, like there are with faces.

If you're still stuck, see this tutorial I wrote that can hopefully help you and others: http://johnallen.github.io/opencv-object-detection-tutorial/

JohnAllen
  • 7,317
  • 9
  • 41
  • 65