Training cascade classifier: Can not get new positive sample

asked 2016-05-21 14:42:50 -0500

I'm trying to create custom haar classifier. I have opencv compiled on my machine.

I have 435 positive images and 4437 negatives (yeah, I know, probably waaaay to much), all of them grayscaled.

Now, my directory structure looks like this

opencv_createsamples
opencv_traincascade
positives.txt
negatives.txt
positives/
    V-train001.ppm
    ...
negatives/
    V-train001.ppm
    ...

negatives.txt looks like that:

./negatives/A-train0426.ppm
./negatives/Point-train1035.ppm
...

positives.txt:

positives/V-train362.ppm 1 1 1 66 76
positives/V-train227.ppm 1 1 1 66 76
positives/V-train154.ppm 1 1 1 65 76

Now, I'm creating samples with the following command:

novy@novy-K53SV:~/Downloads/opencv-3.1.0/build/bin$ ./opencv_createsamples  -info positives.txt -vec sample.vec  
Info file name: positives.txt
Img file name: (NULL)
Vec file name: sample.vec
BG  file name: (NULL)
Num: 1000
BG color: 0
BG threshold: 80
Invert: FALSE
Max intensity deviation: 40
Max x angle: 1.1
Max y angle: 1.1
Max z angle: 0.5
Show samples: FALSE
Width: 24
Height: 24
Create training samples from images collection...
positives.txt(436) : parse errorDone. Created 435 samples

So it looks like samples have been created successfully.

However, when I'm trying to train my classifier I see the following:

novy@novy-K53SV:~/Downloads/opencv-3.1.0/build/bin$ ./opencv_traincascade -data haarcascade -vec sample.vec -bg negatives.txt -nstages 20 -nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 200 -nneg 500 
PARAMETERS:
cascadeDirName: haarcascade
vecFileName: sample.vec
bgFileName: negatives.txt
numPos: 2000
numNeg: 1000
numStages: 20
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC

===== TRAINING 0-stage =====
<BEGIN
POS current samples: 41OpenCV Error: Bad argument (Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
) in get, file /home/novy/Downloads/opencv-3.1.0/apps/traincascade/imagestorage.cpp, line 157
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/novy/Downloads/opencv-3.1.0/apps/traincascade/imagestorage.cpp:157: error: (-5) Can not get new positive sample. The most possible reason is insufficient count of samples in given vec-file.
 in function get

Aborted (core dumped)435

Am I missing something? Also, how should i set npos and nneg?

edit retag flag offensive close merge delete

Comments

-numPos should be 0.9 * myVecFileCount

can gravatar imagecan ( 2016-05-23 01:23:12 -0500 )edit