Unable to train an usable cascade
I'm trying to detect a pattern using opencv_createsamples and opencv_traincascade, but i cant get it to work..And i dont know what i am doing wrong. The pattern to detect could be just anything, as it'll be printed and sheets of paper containing the pattern is what the final application should detect. So, i just create a sample pattern with gimp (some coloured circles), and save it (w:400, h:400) Then, from than single image, i use the following command line to create positives:
opencv_createsamples -img pos/1.png -bg newNeg.txt -maxxangle .15 -maxyangle .15 -maxzangle .15 -num 1000 -vec positives.vec -w 40 -h 40
As background, i use random photos (with random sizes), and run the trainer with:
opencv_traincascade -precalcValBufSize 2048 -precalcIdxBufSize 2048 -data data -vec positives.vec -bg newNeg.txt -numStages 7 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 400 -numNeg 800 -w 40 -h 40 -featureType LBP
The problems are: - The train process takes just 10 seconds.It ends at Stage two (max, stage three, depending on if i use LBP or HAAR) - Looks like just 1 feature is being used. - The cascade file is about 2K
Maybe, being such a simple object, that is right...But then, testing the cascade with an image containing the pattern (200x200) and trying to detect it with
detectMultiScale(frame, results, 1.1, 3, 0, Size(100, 100));
the results collection contains 50 matches!
What am i doing wrong?
If your training used images are much smaller than the image which the detection runs on it will probably give you many false results, try resizing the tested image to be slightly bigger than the trained one (you can use resize() function), as for the training steps, declare -w 24 -h 24 for rectangular images and use more positives than negatives. this is how I got the best results in training similarly to your case.