Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
663 views
in Technique[技术] by (71.8m points)

opencv - How to train cascade properly

What is the posible reason of "Required leaf false alarm rate achieved. Branch training terminated." The folowing command for training:

for creating samples

-img imgs/CHE_one_wb.jpg -num 300 -bg imgs/negat.dat -vec imgs/vector.vec -info imgs/smpl/info.txt -maxxangle 0.1 -maxyangle 0 -maxzangle 0.1 -maxidev 100 -bgcolor 255 -bgthresh 0 -w 20 -h 35

-img imgs/CHE_one_wb.jpg -num 300 -bg imgs/negat.dat -info imgs/smpl/info.txt -maxxangle 0.1 -maxyangle 0.1 -maxzangle 0.1 -maxidev 100 -bgcolor 255 -bgthresh 0 -w 20 -h 35

for train

-data imgs/cascade/ -vec imgs/vector.vec -bg imgs/negat.dat -numPos 200 -numNeg 40 -numStages 10 -featureType LBP -maxFalseAlarmRate 0.9 -w 20 -h 35

RESULT OF TRAINING

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have achieved my goal and trained good cascade.

  1. First you need a couple of original samples (don't use one and multiply it with create samples). I have used 10 different photos of beer bottles, for each I have created 200 hundred samples, then I have combined all samples in one vector file with 2000 samples.
  2. -w 20 -h 35 should match aspect ratio of your original image
  3. Relation of positive samples to negative should be around 2:1 (there should be more positive samples)
  4. Number of stages you should chose by yourself (for me it is 12-13). The more stages you set the more precisely will be your cascade, but you can also overtrain your cascade and it won't find anything. The precision of your cascade is shown by acceptanceRatio on the last stage it should be around this value 0.000412662 or less.

But if you get acceptanceRatio like this 7.83885e-07 your cascade is probably overtrained and it wont find anything, try to set less stages.

!!! And one more important thing, when you train your cascade you should have more than one feature on your stage beginning from 2 or 3 stage. If you have only one feature you wont get good cascade. You should work on your training images (negative and positive samples). Normal training will look like this:

enter image description here

For training I have used -data imgs/cascade/ -vec imgs/vector.vec -bg imgs/negat.dat -numPos 1900 -numNeg 900 -numStages 12 -featureType HAAR -minHitRate 0.999 -maxFalseAlarmRate 0.5 -w 24 -h 30 command

Both features types work almost equals sometimes HAAR is a little bit better but it is significant slower than LBP.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...