Vin
Vin

Reputation: 45

Training Cascade classifier to detect a paper

I am trying to train a cascade classifier to detect a paper (8.5"x11") on a window (real house windows). Basically, I am trying to measure the width and height of the windows based on the paper. Once I detected the paper, I can get the width and height of the window through simple ratio calculation (since paper is fixed size)

I tried using just plain paper with no luck. It could detect the paper but also some random objects. It wasn't too reliable and the training only took 31 minutes. Positive samples were generated from 15 different pictures of paper (cropped). Negative samples are 300x300 window images. Parameters: -numStages 1 -nsplits 2 -minHitRate 0.995 -maxFalseAlarmRate 0.9 -numPos 400 -numNeg 400 -w 62 -h 80

Now I am trying to detect same paper size but with printed object on it (to provide some patterns). Basically, I printed a big Android logo and tried to train the cascade classifier to detect it. Here's my parameters: -numStages 1 -nsplits 2 -minHitRate 0.995 -maxFalseAlarmRate 0.9 -numPos 890 -numNeg 890 -w 62 -h 80 (negative images are in 150x150 pixel resolution)

So I got better results than that of plain paper. I tried to input some of the positive samples (generated by opencv_createsamples) to the cascade classifier and it detects the paper (printed Android) with high accuracy. The problem occurs when I input a real image (picture of a window with the Android paper), the classifier does not detect the paper at all.

Take note that when I input the real image, I resize it to 150x150, so the object to detect (paper) becomes even smaller (around 31x40) and I tried to set the minimum size parameter (in detectMultiScale) to 31x40.

Also, when I try to increase the number of stages, it gives me a 'required leaf false alarm rate achieved' error no matter how much I experiment with -minHitRate and -MaxFalseAlarmRate parameters. Even with these two parameters are set to very low values (0.3 and 0.3 respectively).

Do you guys have any suggestions? What else should you think I try? I am thinking retraining the system with more complex pattern, would that be helpful? I just need some opinions because I have been training my classifier for 3 weeks with more than 50x attempts trying different parameters and image sizes. I am just tired and ran out of ideas to try...

Thanks in advance.

Upvotes: 2

Views: 964

Answers (1)

Swastik Padhi
Swastik Padhi

Reputation: 1909

Keep the following points in mind while training and you should achieve good results-

  1. Specify only the parameters that you can't do without such as

    -numPos
    -numNeg

    Use the default values for other parameters like

    -minHitRate
    -maxFalseAlarmRate
    -weightTrimRate
    -maxDepth
    -maxWeakCount

    Once you have generated a classifier successfully, you can play around with the other values.

  2. Get a good number of original positive samples and negative samples rather than creating them from a small number of samples using opencv_createsamples as training the classifier with the same samples again and again does not increase its accuracy. Also note that -numPos is not the total number of positive samples present in the .vec file. Instead, it is the number of positive samples to be fed into each stage of classifier training so this number should be somewhat less than the total number of positive samples,

  3. The property of cascade classifiers is that they use a series of weak classifiers in order to provide good classification at low computation costs. Hence, it is very important that you train your classifier through a sufficient number of stages otherwise, it would not work.

  4. Check the amount of free memory (RAM) on your system and specify the following parameters accordingly-

    -precalcValBufSize
    -precalcIdxBufSize

    So, if you have 1GB of free memory, you can split it into halves. Do keep in mind that you should not consume all of the free memory otherwise your system might experience failures or the training might terminate prematurely due to insufficient memory.

Further reading: How to train cascade properly

Upvotes: 3

Related Questions