Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV traincascade for LBP training

I am trying to create head detector using LBP features in OpenCV, using traincascade utility. The head detector, I hope, will result in something similar to OpenCV's profileface created by Vladim Pivarevsky. I want to recreate the model because current model only handle frontal and left side face.

I follow Naotoshi Seo tutorial and use dataset from Irshad Ali website. Unfortunately, resulting model performs slowly with lots of false detection.

The traincascade is run as follow:

opencv_traincascade -data "data" -vec "samples.vec" -bg "out_negatives.dat" -numPos 26000 -numNeg 4100 -numStages 16 -featureType LBP -w 20 -h 20 -bt GAB -minHitRate 0.995 -maxFalseAlarmRate 0.3 -weightTrimRate 0.95 -maxDepth 1 -maxWeakCount 100 -maxCatCount 256 -featSize 1

I tried using other dataset, now frontal face from http://fei.edu.br/~cet/facedatabase.html but the result is still same: slow detection and lot of false positives.

Anybody have knowledge or experience in creating cascade haar/lbp model? Please give any suggestion so I can improve the accuracy of the model. I tried using OpenCV built-in model, and the result is good (lbpfrontalface.xml). Thank you so much!

like image 567
bonchenko Avatar asked Jun 19 '13 07:06

bonchenko


3 Answers

The best way is "trial and error"... You really need differents faces, and the greater difference is better. You can take one face and via createsamples do many faces. But this way, you never have good cascade. You should have many different faces, and if they will not be enough, you can increase them through createsamples. For example, you have 500 different faces by createsamples you can do with them 5000, then perhaps cascade will satisfy you.

About start training: to much positive:) or too few negative. You need for example 5000 pos and 2500 neg (pos = 2*neg). At least in my case it was the best choice.

like image 184
McBodik Avatar answered Nov 04 '22 02:11

McBodik


In short, it's normal to get a lot of false positives after stage 1 of modeling. You need to take those false positives and add them to the negative dataset and repeat the modeling (stage 2). This is called hard negative mining. It is essential. You can multiply the false negatives by incrementally rotating them through 360 degrees.

Three other important points: 1) opencv_createsamples is bad for faces; 2) Use negatives that are challenging (suitable); 3) LBP is second rate in many contexts.

  1. Faces are fairly symmetrical and never display a trapezium like distortion in when photographed. Use very small angles if you must, like 0.02 radians. Further, you will find when you look at the images in the .vec file that the background fill around the distorted edges looks quite unnatural.

  2. Not only the number of negatives is important, but the quality of the of the negatives is important. Faces are smooth compared to many negative images (eg trees, Rocky Mountains etc) so it is relatively easy to distinguish a face from a pine tree at a distance. However, you will get a lot of false positives from smooth surfaces like walls. It is best to include challenging images in the negative dataset. I found that the best background were images of smooth painted plasterboard walls. Take a video whilst walking along some walls, use ffmpeg to chop it up into a heap of images. Again, you can multiply these negatives by incrementally rotating them through 360 degrees, then flip and rotate again.

  3. Be patient, use HAAR not LBP.

AI is all the rage now, just divide up 100,000 uncropped images into folders for the corresponding classes and start training your model. However, you may find this approach only gets 98-99% correct classification rate. Way too many false positives. You will get better results with much less data doing what I said above (whether using HAAR cascades or neural nets). This is the real data science work: shrewd selection of the negative and positive datasets and the time consuming work in defining the boundary boxes.

like image 29
Davo Avatar answered Nov 04 '22 00:11

Davo


It will be slow, relatively as it starts at 20x20 and searches the whole image then gets slightly bigger, searches again etc. - try increasing your sample size to decrease the time to run.

I also noticed you don't have anywhere near as many bg images as positive. Try increasing that to at least the same as your positive and that should help.

I suggest also cracking out the haar features and see if that gives you any results.

everything else seems fine without looking at your input data

like image 28
GPPK Avatar answered Nov 04 '22 02:11

GPPK