# Training a lbp detector/classifier

Hi!

I've been trying to create an LBP detector/one class classifier and I am running into some issues. I currently have 500 positive and 1500 negative images with a resolution of 1929x1341. The positives are .bmp images of a "dummy fish" in different postures taken in a watertank with a plain white background. The negatives are all random grayscale .jpg images.

Two examples of test images can be seen here:

To supply the positive samples i have used the tool objectmarker to mark out the region of interest in each of the positive images and save this in a positive.txt file. The .txt file is formated like this:

data/pos_n.bmp 1 x y width height


The negatives are sent to the opencv_traincascade.exe utility from OpenCV by means of a .bg file. The file is formated like this:

path/neg_n.jpg


The opencv_createsamples.exe tool is then used to create the positive samples needed by the trainlbpcascade.exe tool. The call for this is:

opencv_createsamples.exe -info positive/info.txt -vec vector/dummy_fish_vector.vec -num 515 -w 75-h 30


The reason why the -w and -h is not equal is because my "dummy fish" has a rectangular bounding region. The vector dummy_fish_vector.vec retrieved from createsamples.exe is then used to train the classifier using the trainlbpcascade.exe tool. The call to train the classifier is:

opencv_traincascade.exe -data objectDetector -vec vector/dummy_fish_vector.vec -bg negative/bg.txt -numPos 450 -numNeg 2000 -numStages 12 -stageType LBP -minFalseAlarmRate 0.3 -minHitRate 0.96 -featureType LBP - -w 75 -h 30 -bt DAB


The cascade I receive from this call is then used in the objectdetect sample program and supplied a stream of images. My problem is that I receive alot of false negatives using these calls, along with the real positive (if the fish is in the image). Can you see any obvious reasons as to why this should happen? I hope I have supplied sufficient information on the problem. I have also noticed that when I try to train the classifier it stops at a very early stage, and does not complete all of the stages. I have tried a variety of calls to train the classifier with 4-12 stages, but they all seem to stop early. Any help?

edit retag close merge delete

If you want them to train longer, increase acceptanceRatioBreakValue or just do not set it. Also false negatives are avoided by adding more positive training data.

( 2016-10-20 07:57:09 -0500 )edit

Thank you for the response! Im in the process of acquiring more positive training data. Still, I have some more questions:

• When I run the classifier on the image stream it seems to give alot of false positives of the background, where no parts of the fish resides. Could this be solved by adding positive training data of the same test fish with different backgrounds?

• When choosing negative training data, is it favorable to have random images, or should the images contain a "natural" background? Also, should these be grayscale or color images?

• I ommited the -acceptanceRatioBreakValue in my more recent call to traincascade, but the training still only continues until at most stage 4. I am also not setting -mode or -maxDepth.

I hope you are able to answer some of this :)

( 2016-11-10 05:59:27 -0500 )edit

trainlbpcascade.exe is no official tool.Where did you get it?

( 2016-11-10 08:53:26 -0500 )edit

Oh! Sorry I didnt realize that it was still named that. Its just plain old opencv_traincascade. I just had some trouble earlier and had to rename the exe. I'll edit it in the main post.

( 2016-11-10 08:56:33 -0500 )edit