Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Train dataset for temp stage can not be filled." while using traincascade tool of OpenCV

Tags:

opencv

I'm building the opencv_traincascade.exe tool from source code (OpenCV 2.4.0) using vs2010 on windows 7. I want to train a LBP classifier, so I'm using opencv_traincascade.exe with the following arguments

-data D:\OpenCV\Classifiers\lbpclassifier1\temp\data -vec D:\OpenCV\Classifiers\lbpclassifier1\temp\samples.vec -bg D:\OpenCV\Classifiers\lbpclassifier1\temp\negative\infofile.txt -numPos 40 -numNeg 40 -precalcIdxBufSize 500 -precalcValBufSize 500 -stageType BOOST -featureType LBP -w 24 -h 24

The error message that I get is:

PARAMETERS:
cascadeDirName: D:\OpenCV\Classifiers\lbpclassifier1\temp\data
vecFileName: D:\OpenCV\Classifiers\lbpclassifier1\temp\samples.vec
bgFileName: D:\OpenCV\Classifiers\lbpclassifier1\temp\negative\infofile.txt
numPos: 2
numNeg: 40
numStages: 20
precalcValBufSize[Mb] : 500
precalcIdxBufSize[Mb] : 500
stageType: BOOST
featureType: LBP
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.995
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100

===== TRAINING 0-stage =====
<BEGIN
POS count : consumed   2 : 2
Train dataset for temp stage can not be filled. Branch training terminated.

This question has been asked before : Error while using opencv_train cascade , and the solution suggested there viz. making the number of positive and negative samples equal doesn't help in this case.

I thought that the error might be related to this bug : http://code.opencv.org/issues/1834 So, I downloaded the latest release of imagestorage.cpp from that page and rebuilt the opencv_traincascades tool. Also, the total number of samples in the .vec file is 45. So as suggested in this comment I have changed the numPos argument to 2, so that I don't run out of samples in the .vec file. The number of samples in the .vec file is 45.

Any help is much appreciated. Thanks.

like image 633
Shishir Joshi Avatar asked Jul 10 '12 11:07

Shishir Joshi


3 Answers

First, for me too, the error was with the bg file. I use Opencv 2.4.10.1.

I got the error when I specified the absolute path to the bg file in the command (like the author of the post). Looks like the authors did a really, really crappy job on figuring out the full negative image paths. One simple workaround is to simply CD to the dir of the .info file (note -bg infofile.txt)

cd D:\OpenCV\Classifiers\lbpclassifier1\temp\negative
train_cascade -data D:\OpenCV\Classifiers\lbpclassifier1\temp\data -vec D:\OpenCV\Classifiers\lbpclassifier1\temp\samples.vec -bg infofile.txt -numPos 40 -numNeg 40 -precalcIdxBufSize 500 -precalcValBufSize 500 -stageType BOOST -featureType LBP -w 24 -h 24
like image 117
etoropov Avatar answered Nov 09 '22 00:11

etoropov


opencv_traincascade is trying to read the Negative folder images in the current folder. Hence you have to transfer the opencv_traincascade.exe into negative/ images folder.

For example:

- opencv_traincascade.exe -data C:\Users\home\Documents\Face_Detection\HaarTrain\cascades -vec C:\Users\home\Documents\Face_Detection\HaarTrain\vector\vector.vec -bg bg.txt -numPos 130 -numNeg 500 -numStages 10 -precalcValBufSize 1024 -precalcIdxBufSize 1024
like image 26
Kiran Kumar Avatar answered Nov 09 '22 02:11

Kiran Kumar


I am also learning how to use OpenCV object detection tools.

I noticed that if the bg file (in your case "D:\OpenCV\Classifiers\lbpclassifier1\temp\negative\infofile.txt") has a wrong format or contains a entry with non-existent file, opencv_traincascade produces error.

Hope it helps.

like image 23
Hiro Avatar answered Nov 09 '22 00:11

Hiro