Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, OpenCV: unable to make custom LBP cascade using opencv_traincascade

I am using opencv 2.4.4 installed via macports with python 2.7.5 on a mac os x 10.7.5.

I want to train a cascade to look for male frontal faces. But I am getting the terminate called throwing an exceptionAbort trap: 6 error. I request the SO community help me figure out what might be going wrong.

The negative (background) image are taken from google: googleImages_noFaces (293 images)

The positive images are taken from Karolinska database: trainingSet (70 images)

I created a text file which indicates the relative location of background images: bgDesc.txt

I also created a text file indicating the relative location, number of positive instances in the image (which is always 1) and bounding region of the object (which is the entire image): maleDesc.txt

All these files can be downloaded from here.

The organization of the files is in this form:

/trainingSet
    image1.jpg
    image2.jpg
    .
    .
    .

/googleImages_noFaces
    image1.jpg
    image2.jpg
    .
    .
    .

/cascadeFiles

maleDesc.txt
bgDesc.txt

when I use opencv_createsamples a maleDesc.vec file is successfully created with the following line:

opencv_createsamples -vec maleDesc.vec -info maleDesc.txt -bg bgDesc.txt -num 70 -w 24 -h 24

if I use -show parameter I can see that 24x24 pixel images are created.

I then try

opencv_traincascade -data cascadeFiles -vec maleDesc.vec -bg bgDesc.txt -numPos 70 - numNeg 293 -numStages 1 -precalcValBufSize 500 -precalcIdxBufSize 500 -featureType LBP -w 24 -h 24

Which gives me an error.

I have tried different values of -numPos such as 10, 20 and so on up to 70 along with different values of -numNeg as 30, 60 and so on up to 293. I have tried to use numPos values that are less than numNeg values and even those which are greater than. I have also tried different -numStages values like 1, 5, 10, 20 and 100 but in all of these attempts I get the same error.

I have not tried different values of -minHitRate, -maxFalseAlarmRate, -weightTrimRate, -maxDepth, -maxWeakCount because I don't really understand how they influence the behavior of opencv_traincascade algorithm.

Any help is much appreciated :)

like image 543
samkhan13 Avatar asked Oct 19 '13 10:10

samkhan13


1 Answers

the terminate called throwing an exceptionAbort trap: 6 error was due to a typo. i managed to replicate the behavior and verify it in the bellow code

opencv_traincascade -data cascadeFiles -vec maleDesc.vec -bg bgDesc.txt -numPos 70 - numNeg 293 -numStages 1 -precalcValBufSize 500 -precalcIdxBufSize 500 -featureType LBP -w 24 -h 24

there was a space between - and numNeg which should have been -numNeg

additionally, the training proceeds even with very low samples but the numPos must be twice of numNeg

refer to this SO answer for more clarification on the haar and lbp training process: https://stackoverflow.com/a/16834901/1463143

two weeks and 50 reputation as bounty got wasted because of a typo :|

like image 146
samkhan13 Avatar answered Nov 10 '22 00:11

samkhan13