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

前端 未结 10 995
灰色年华
灰色年华 2020-12-16 20:35

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

相关标签:
10条回答
  • 2020-12-16 20:41

    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
    
    0 讨论(0)
  • 2020-12-16 20:44

    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
    
    0 讨论(0)
  • 2020-12-16 20:45

    I hope to close this question. For those who stumbled over this as well. I know its old. I debugged the traincascade and found, that at some point the following line:

    src = imread( imgFilenames[last++], CV_LOAD_IMAGE_GRAYSCALE );
    

    returns a null mat. This line should read the background images.

    This bug occures, if you build traincascade.cpp as debug and are using the release libs and dlls of opencv. (The other way around shouldn't work as well.

    0 讨论(0)
  • 2020-12-16 20:46

    I had the exact same problem. The issue for me was that I created my negatives.txt file using PowerShell which writes a BOM to the file. The BOM trips up the opencv_traincascade program when it tries to read the file and causes it to not find any of the images. I converted the file to UTF-8 using Notepad++ and that fixed the issue.

    0 讨论(0)
  • 2020-12-16 20:47

    I had this similar problem which gives error:

    POS count : consumed   50 : 50
    Train dataset for temp stage can not be filled. Branch training terminated.
    

    The problem was that, my bg.txt was generated in a Windows system using \r for next line. When I tried to use opencv_traincascade in Ubuntu, it read '\r' into the string for filelist, thus in CvCascadeImageReader::NegReader::nextImg() , the line src = imread(imgFilenames[last++], 0); (as xeed mentioned) did not work.

    My fix was to add str.erase(std::remove(str.begin(), str.end(), '\r'), str.end()); before imgFilenames.push_back(dirname + str); in imagestorage.cpp

    I hope this helps, if anyone still struggles.

    0 讨论(0)
  • 2020-12-16 20:47

    CentOS Linux release 7.4.1708 (Core)

     opencv_traincascade -data haarcascadeHAAR 
    -vec samples.vec -bg Bad.dat -numPos 1500 -numNeg 3000 
    -numStages 35 -minHitRate 0.95 -maxFalseAlarmRate 0.5 
    -mode ALL -w 20 -h 20 
    -precalcValBufSize 2048 -precalcIdxBufSize 4096
    

    System return responce: Train dataset for temp stage can not be filled. Branch training terminated. Cascade classifier can't be trained. Check the used training parameters.

    This trouble was in OpenCV 2.4.6 and 3.1.0. Resolution next (for my case)- I create file Bad.dat on windows host, when I copy this file on unix I switch b-slash to slash (:%s/\// for Vi), but catch same result. When I change EOL from Win (CR LF) to Nix (LF) - traincascade launched successfuly.

     $ file Bad.dat
    Bad.dat: ASCII text, with CRLF line terminators
    
    $ dos2unix Bad.dat
    dos2unix: converting file Bad.dat to Unix format ...
    
    $ file Bad.dat
    Bad.dat: ASCII text
    

    The process works well reason - check you Bad.dat (file in -bg param)

    0 讨论(0)
提交回复
热议问题