Coder Social home page Coder Social logo

opencv-haar-classifier-training's Introduction

Train your own OpenCV Haar classifier

Important: This guide assumes you work with OpenCV 2.4.x. Since I no longer work with OpenCV, and don't have the time to keep up with changes and fixes, this guide is unmaintained. Pull requests will be merged of course, and if someone else wants commit access, feel free to ask!

This repository aims to provide tools and information on training your own OpenCV Haar classifier. Use it in conjunction with this blog post: Train your own OpenCV Haar classifier.

Instructions

  1. Install OpenCV & get OpenCV source

     brew tap homebrew/science
     brew install --with-tbb opencv
     wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
     unzip opencv-2.4.9.zip
    
  2. Clone this repository

     git clone https://github.com/mrnugget/opencv-haar-classifier-training
    
  3. Put your positive images in the ./positive_images folder and create a list of them:

     find ./positive_images -iname "*.jpg" > positives.txt
    
  4. Put the negative images in the ./negative_images folder and create a list of them:

     find ./negative_images -iname "*.jpg" > negatives.txt
    
  5. Create positive samples with the bin/createsamples.pl script and save them to the ./samples folder:

     perl bin/createsamples.pl positives.txt negatives.txt samples 1500\
       "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\
       -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"
    
  6. Use tools/mergevec.py to merge the samples in ./samples into one file:

     python ./tools/mergevec.py -v samples/ -o samples.vec
    

    Note: If you get the error struct.error: unpack requires a string argument of length 12 then go into your samples directory and delete all files of length 0.

  7. Start training the classifier with opencv_traincascade, which comes with OpenCV, and save the results to ./classifier:

     opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\
       -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\
       -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\
       -precalcIdxBufSize 1024
    

    If you want to train it faster, configure feature type option with LBP:

      opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\
       -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\
       -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\
       -precalcIdxBufSize 1024 -featureType LBP
    

    After starting the training program it will print back its parameters and then start training. Each stage will print out some analysis as it is trained:

    ===== TRAINING 0-stage =====
    <BEGIN
    POS count : consumed   1000 : 1000
    NEG count : acceptanceRatio    600 : 1
    Precalculation time: 11
    +----+---------+---------+
    |  N |    HR   |    FA   |
    +----+---------+---------+
    |   1|        1|        1|
    +----+---------+---------+
    |   2|        1|        1|
    +----+---------+---------+
    |   3|        1|        1|
    +----+---------+---------+
    |   4|        1|        1|
    +----+---------+---------+
    |   5|        1|        1|
    +----+---------+---------+
    |   6|        1|        1|
    +----+---------+---------+
    |   7|        1| 0.711667|
    +----+---------+---------+
    |   8|        1|     0.54|
    +----+---------+---------+
    |   9|        1|    0.305|
    +----+---------+---------+
    END>
    Training until now has taken 0 days 3 hours 19 minutes 16 seconds.
    

    Each row represents a feature that is being trained and contains some output about its HitRatio and FalseAlarm ratio. If a training stage only selects a few features (e.g. N = 2) then its possible something is wrong with your training data.

    At the end of each stage the classifier is saved to a file and the process can be stopped and restarted. This is useful if you are tweaking a machine/settings to optimize training speed.

  8. Wait until the process is finished (which takes a long time — a couple of days probably, depending on the computer you have and how big your images are).

  9. Use your finished classifier!

     cd ~/opencv-2.4.9/samples/c
     chmod +x build_all.sh
     ./build_all.sh
     ./facedetect --cascade="~/finished_classifier.xml"
    

Acknowledgements

A huge thanks goes to Naotoshi Seo, who wrote the mergevec.cpp and createsamples.cpp tools and released them under the MIT licencse. His notes on OpenCV Haar training were a huge help. Thank you, Naotoshi!

References & Links:

opencv-haar-classifier-training's People

Contributors

arthuraouille avatar hskang9 avatar kevinhughes27 avatar mrnugget avatar tomvdv avatar whackashoe avatar xjdeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencv-haar-classifier-training's Issues

File not found - '*.jpg'

When i execute the following command in cmd it gives the error "File not found - '.jpg'"
-> find ./positive_images -iname "
.jpg" > positives.txt
-> find ./negative_images -iname "*.jpg" > negatives.txt
please help me with this issue

Please Help

Will this code help for windows???
please help its urgent

Can anyone help me out with foll error?

===== TRAINING 0-stage =====
<BEGIN
OpenCV 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 /opt/conda/conda-bld/opencv_1491943970124/work/opencv-3.1.0/apps/traincascade/imagestorage.cpp, line 157
terminate called after throwing an instance of 'cv::Exception'
what(): /opt/conda/conda-bld/opencv_1491943970124/work/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)

Training not happening

Hello,
im getting the following error after executing the command to start training.

terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
Aborted (core dumped)

Could you please guide me. I have 80 samples of size 60x60 and have executed commands till acquiring the vector file successfully.

str.unpack error

Hi,

I have gotten to the step where, i need to combine the individual vector files, into a single vector file using the mergevec.py program.
I get an error at line 121 of the program:

val = struct.unpack('<iihh', content[:12])

The error is:

TypeError: a bytes-like object is required, not 'str'

My python version is: 3.6.0
Please can you help?

I got multiple object detections without actual image detection.

I'm ran this script but I got multiple object detections without actual image detection.

chmod +x build_all.sh
./build_all.sh
./facedetect --scale=2 --cascade="/Users/ZERO/RM1/classifier/cascade.xml"

screenshot 2016-09-05 13 12 18

I got 51 positive images and 632 negative images. I ran this command to train the model (only 10 stages).

opencv_traincascade -data /Users/ZERO/RM1/classifier -vec /Users/ZERO/RM1/samples.vec -bg /Users/ZERO/Dropbox/RM1/negative_images/negatives.txt -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

Please advice. Thank you.

would this work with opencv 3.1

hi I am using opencv3.1-dev. I can not find the folder haartraining under ~opencv/apps/ directory. I searched required files in opencv github repository but i could not find it
unnirajendran-SVF15318SNW% cd opencv/apps
unnirajendran-SVF15318SNW% ls
annotation createsamples traincascade CMakeLists.txt interactive-calibration
unnirajendran-SVF15318SNW% ls -l
total 20 drwxrwxr-x 2 unnirajendran unnirajendran 4096 May 6 14:47 annotation -rw-rw-r-- 1 unnirajendran unnirajendran 209 May 6 14:47 CMakeLists.txt drwxrwxr-x 3 unnirajendran unnirajendran 4096 May 15 13:32 createsamples drwxrwxr-x 2 unnirajendran unnirajendran 4096 May 6 14:47 interactive-calibration drwxrwxr-x 2 unnirajendran unnirajendran 4096 May 15 13:41 traincascade
unnirajendran-SVF15318SNW%

opencv_traincascade Error - classifier/params.xml can not be opened

Hello,

After the opencv_traincascade command I have this error message :
Parameters can not be written, because file classifier/params.xml can not be opened.

I think that the folder have to be created by hand, no ?

[EDIT] I've got it.
I was not using your tool from the default folder.
Despite for mergevec which is creating "samples" folder, opencv_traincascade is not creating "classifier" folder.

Compiling mergevec.cpp failing on OSX 10.9

The compiling of mergevec.cpp fails on OSX 10.9 with the following errors
Command:
g++ pkg-config --libs --cflags opencv -I. -o mergevec mergevec.cpp\ cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp\ cvhaartraining.cpp\ -lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect

Error:
ld: library not found for -llibtbb.dylib clang: error: linker command failed with exit code 1 (use -v to see invocation)

Since I do want to run opencv with tbb my solution was simply to

  1. Go through steps 1 - 5 in the read me (create samples)
  2. Uninstall opencv (brew uninstall opencv)
  3. Install opencv without tab (brew install opencv)
  4. Compile mergevec.cpp
  5. Uninstall opencv (brew uninstall opencv)
  6. Install opencv with tbb (brew install --with-tbb opencv)

This works fine, but is subpotimal.
I couldn’t for the life of me get the compiler to link libtbb. Not sure whats wrong.
Can I help with providing information of any sort?

opencv_createsamples not creating anything inside the 'samples' folder

when I run the command:

perl bin/createsamples.pl positives.txt negatives.txt samples 1500
"opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

it doesn't create anything inside the 'samples' directory. still i m facing same issue .. Please help me

I m running this command on REDHAT
Python version : 2.7 and opencv version :3.4.4
Thanks in Advance

mergevec.py for Python 3.x

Hi. When I try to execute mergevec.py the shell returns TypeError: 'str' does not support the buffer interface" for lines 170 and 120

Turns out there is a distinct incompatibilty between Py 2.x and 3.x that causes this error. How do I modify the py script to make it compatible with my Python 3.4?

Error

Hi , I'm using mac. I get error when i execute this statement in terminal
perl bin/createsamples.pl positives.txt negatives.txt samples 1700
"opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 24 -h 24"
Error is : sh: -c: line 0: syntax error near unexpected token `(' .
What could be the issue ?

vec files can't be created

hey guys when i python ./tools/mergevec.py -v samples/ -o samples.vec
i got an error like this
Vec files to be merged could not be found from directory: samples

Cannot create sample.vec

I already run

perl bin/createsamples.pl positives.txt negatives.txt samples 1500
"opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

but there is no sample.vec created, how to fix this sir ? i hope you can help my problems

osx 10.9 opencv build error

Hi,

I've followed the instructions, but I'm receiving the following errors on step 6 when attempting to compile the mergevec app.

I've built the open cv distribution successfully but I'm still receiving these errors.

It seems like g++ can't find opencv.

mergevec.cpp:1:10: fatal error: 'cv.h' file not found
#include <cv.h>
         ^
1 error generated.
In file included from cvboost.cpp:64:
./_cvcommon.h:45:10: fatal error: 'opencv2/core/core.hpp' file not found
#include "opencv2/core/core.hpp"
         ^
1 error generated.
In file included from cvcommon.cpp:42:
./_cvcommon.h:45:10: fatal error: 'opencv2/core/core.hpp' file not found
#include "opencv2/core/core.hpp"
         ^
1 error generated.
In file included from cvsamples.cpp:49:
In file included from ./_cvhaartraining.h:51:
./_cvcommon.h:45:10: fatal error: 'opencv2/core/core.hpp' file not found
#include "opencv2/core/core.hpp"
         ^
1 error generated.
In file included from cvhaarclassifier.cpp:48:
In file included from ./_cvhaartraining.h:51:
./_cvcommon.h:45:10: fatal error: 'opencv2/core/core.hpp' file not found
#include "opencv2/core/core.hpp"
         ^
1 error generated.
In file included from cvhaartraining.cpp:49:
In file included from ./_cvhaartraining.h:51:
./_cvcommon.h:45:10: fatal error: 'opencv2/core/core.hpp' file not found
#include "opencv2/core/core.hpp"
         ^
1 error generated.

face_cascade = new cv.CascadeClassifier(classifier);

I got this error message when execute node script

/Users/ZERO/node_modules/opencv/lib/opencv.js:22
    face_cascade = new cv.CascadeClassifier(classifier);
                   ^

TypeError: Error loading file
    at TypeError (native)
    at Matrix.detectObject (/Users/ZERO/node_modules/opencv/lib/opencv.js:22:20)
    at /Users/ZERO/RM1/index.js:14:8
    at /Users/ZERO/RM1/index.js:13:6
    at Array.forEach (native)
    at Object.<anonymous> (/Users/ZERO/RM1/index.js:12:12)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

My script

var cv = require('opencv');

var color       = [0, 255, 0];
var thickness   = 2;
var cascadeFile = '/Users/ZERO/RM1/classifier/cascade.xml';

var inputFiles = [
  '/Users/ZERO/RM1/recognize/recognize_this_1.jpg', 
  '/Users/ZERO/RM1/recognize/recognize_this_2.jpg', 
  '/Users/ZERO/RM1/recognize/recognize_this_3.jpg',
  '/Users/ZERO/RM1/recognize/recognize_this_4.jpg', 
  '/Users/ZERO/RM1/recognize/recognize_this_5.jpg', 
  '/Users/ZERO/RM1/recognize/recognize_this_6.jpg'
];

inputFiles.forEach(function(fileName) {
  cv.readImage(fileName, function(err, im) {
    im.detectObject(cascadeFile, {neighbors: 2, scale: 2}, function(err, objects) {
      console.log(objects);
      for(var k = 0; k < objects.length; k++) {
        var object = objects[k];
        im.rectangle(
          [object.x, object.y],
          [object.x + object.width, object.y + object.height],
          color,
          2
        );
      }
      im.save(fileName.replace(/\.jpg/, 'processed.jpg'));
    });
  });
});

Please advice. Thank you.

I can't execute this code: ./build_all.sh

Hello, I have a problem that can't be solved. Can you help me?.
When I tried to run your banana classifier with a terminal, I met the following tips:

Macbook-Pro:~ fcx$ cd ~/opencv-2.4.9/samples/c

Macbook-Pro:c fcx$ chmod +x build_all.sh

Macbook-Pro:c fcx$ ./build_all.sh
**compiling contours.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling convert_cascade.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling delaunay.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling fback_c.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling morphology.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling motempl.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling polar_transforms.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling pyramid_segmentation.c
clang: error: argument to '-l' is missing (expected 1 value)
compiling adaptiveskindetector.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling bgfg_codebook.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling blobtrack_sample.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling facedetect.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling find_obj.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling find_obj_calonder.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling find_obj_ferns.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling latentsvmdetect.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling mser_sample.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling mushroom.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling one_way_sample.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling smiledetect.cpp
clang: error: argument to '-l' is missing (expected 1 value)
compiling tree_engine.cpp
clang: error: argument to '-l' is missing (expected 1 value)**

Where is ./facedetect file location?

I have successfully run and train the classifier, but to save into the file I have a problem.

  1. Where I can find ./build_all.sh file if I am using ubuntu?
  2. I manage by cloning to the repository, but the problem is I can not get file ./facedetect so where is the file location?, I just find facedetect.cmd and I use but not run. How can I find this file in case I have installed openCV before?
  3. In case I failed to save the file to .xml, is it possible to do it later I mean like our trained data is save before writing the file .xml?
    Here is the error message bash: ./facedetect: No such file or directory

Step 1 opencv-haar-classifier-training error

Hi,

  1. I tried step 2 to step 4. Had about 675 positive and1970 negative pictures. I could generate positives.txt and negatives.txt files.
    while running step 5:(below)
    perl bin/createsamples.pl positives.txt negatives.txt samples 1700 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 24 -h 24"
    I am receiving error as below:
    it gave error as:
    Error is: syntax error near unexpected token "(".

  2. I realized that I missed step 1. Hence, I restarted the process and entered the first command as below and got message as below:


root@rajas01:~/rajashaar2# brew tap homebrew/science
W: be careful as root.

========================================================================
You may want to update following environments after installed linuxbrew.

PATH, MANPATH, INFOPATH

(example: /usr/share/doc/linuxbrew-wrapper/examples/profile)

Don't run this as root!
root@rajas01:~/rajashaar2# Don't run this as root!


It indicates a warning as do not run this as root!
I have gone through previous correspondences and unable to locate any solution for this. Am I missing any step here? Please help. (Note: I am trying this on web server installed with Ubuntu.)

Problem with library llibtbb.dylib for mac Users

Based on: http://stackoverflow.com/questions/23363678/ld-library-not-found-for-llibtbb-dylib
Due to a misspell in the opencv.pc, this library is misspelled into the config file of Mac users. Due to that, we get a when running the g++ command:
ld: library not found for -libtbb.dylib

To fix this, it's required to correct the opencv.pc, by putting the correct path of the library. For instance:
/usr/local/lib/libtbb.dylib.

If needed, I can open a PR for this to put into the instruction part.

Only empty vec files

Hello, I’m trying to follow your tutorial to create Haar cascade Training Files but at the step 5, it create 19 .vec files, but their are all empty (0 byte) so the step 6 fail.
I have 20 positive photos and 100 negative photos, all with 4160 x 2340 pixels, so my -w and -h are 128 and 72 (same ratio). All the steps have been done on a linux virtual machine.

I hope you can help my find the problem.

The command:

perl bin/createsamples.pl positives.txt negatives.txt samples 400  "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\
  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72"

The log:

opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234350.jpg -bg tmp -vec samples/20161122_234350.jpg.vec -num 22
Info file name: (NULL)
Img file name: ./positive_images/20161122_234350.jpg
Vec file name: samples/20161122_234350.jpg.vec
BG  file name: tmp
Num: 22
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234654.jpg -bg tmp -vec samples/20161122_234654.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234654.jpg
Vec file name: samples/20161122_234654.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234418.jpg -bg tmp -vec samples/20161122_234418.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234418.jpg
Vec file name: samples/20161122_234418.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234423.jpg -bg tmp -vec samples/20161122_234423.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234423.jpg
Vec file name: samples/20161122_234423.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234305.jpg -bg tmp -vec samples/20161122_234305.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234305.jpg
Vec file name: samples/20161122_234305.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234313.jpg -bg tmp -vec samples/20161122_234313.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234313.jpg
Vec file name: samples/20161122_234313.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234432.jpg -bg tmp -vec samples/20161122_234432.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234432.jpg
Vec file name: samples/20161122_234432.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234219.jpg -bg tmp -vec samples/20161122_234219.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234219.jpg
Vec file name: samples/20161122_234219.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234244.jpg -bg tmp -vec samples/20161122_234244.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234244.jpg
Vec file name: samples/20161122_234244.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234024.jpg -bg tmp -vec samples/20161122_234024.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234024.jpg
Vec file name: samples/20161122_234024.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234659.jpg -bg tmp -vec samples/20161122_234659.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234659.jpg
Vec file name: samples/20161122_234659.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234255.jpg -bg tmp -vec samples/20161122_234255.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234255.jpg
Vec file name: samples/20161122_234255.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234335.jpg -bg tmp -vec samples/20161122_234335.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234335.jpg
Vec file name: samples/20161122_234335.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234633.jpg -bg tmp -vec samples/20161122_234633.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234633.jpg
Vec file name: samples/20161122_234633.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234339.jpg -bg tmp -vec samples/20161122_234339.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234339.jpg
Vec file name: samples/20161122_234339.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234012.jpg -bg tmp -vec samples/20161122_234012.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234012.jpg
Vec file name: samples/20161122_234012.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234021.jpg -bg tmp -vec samples/20161122_234021.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234021.jpg
Vec file name: samples/20161122_234021.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234456.jpg -bg tmp -vec samples/20161122_234456.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234456.jpg
Vec file name: samples/20161122_234456.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1  -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 128 -h 72 -img ./positive_images/20161122_234035.jpg -bg tmp -vec samples/20161122_234035.jpg.vec -num 21
Info file name: (NULL)
Img file name: ./positive_images/20161122_234035.jpg
Vec file name: samples/20161122_234035.jpg.vec
BG  file name: tmp
Num: 21
BG color: 0
BG threshold: 0
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: 128
Height: 72
Create training samples from single image applying distortions...

Can not see finished_classifier.xml file

Dear pro!
I tried to convert a picture to an "image_learning.xml" file
I cloned your project and do step by step, there was no error!

I got the results from "opencv-haar-classifier-training\classifier" folder
There were 1 params.xml file and 9 stage.xml file

image

I wonder where is the finished_classifier.xml ?

Thanks for help!

Ly Hoang Nam

Parameters can not be written, because file classifier/params.xml can not be opened.

I got this kind of error after training stage sixth

Parameters can not be written, because file classifier/params.xml can not be opened.

My command

opencv_traincascade -data /Users/ZERO/samples.vec -bg /Users/ZERO/negative_images/negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

screenshot 2016-09-03 10 46 31

Please advice. Thank you.

OpenCV error : Bad Arguement - Can not get new Positive Sample

I had 76 positive images and 3019 negative images.
I modified the script on step 5 as -

perl bin/createsamples.pl positives.txt negatives.txt samples 1500\
   "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\
   -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 60 -h 80" 

to maintain the ratio as my positive images were of size - 2448 x 3264 pixels.
Samples were created successfully.

On running the script python ./tools/mergevec.py -v samples/ -o samples.vec , I got the error as defined in the README - struct.error: unpack requires a string argument of length 12
All but 2 of the files in the samples directory were of size 0 bytes so I deleted them and re-ran the script. It worked fine.

I then ran the script mentioned -
opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 60 -h 80 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024
Modifying the height and width parameters again.

This time I get the error -

===== TRAINING 0-stage =====
<BEGIN
OpenCV Error: Bad argument (Can not get new positive sample. Seems that vec-file has incorrect structure.
) in get, file /build/opencv-00QkEr/opencv-2.4.9.1+dfsg1/apps/traincascade/imagestorage.cpp, line 165
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/opencv-00QkEr/opencv-2.4.9.1+dfsg1/apps/traincascade/imagestorage.cpp:165: error: (-5) Can not get new positive sample. Seems that vec-file has incorrect structure.
 in function get

Abortedrent samples: 1


struct.error: unpack requires a string argument of length 12

If you get the following error:

Traceback (most recent call last):
  File "opencv-haar-classifier-training/tools/mergevec.py", line 171, in <module>
    merge_vec_files(vec_directory, output_filename)
  File "opencv-haar-classifier-training/tools/mergevec.py", line 134, in merge_vec_files
    val = struct.unpack('<iihh', content[:12])
struct.error: unpack requires a string argument of length 12

then try deleting all vector files of size 0 from your input directory before running it again!

not execute the createsamples.pl

When I execute:

perl bin/createsamples.pl positives.txt negatives.txt samples 1500
"opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

Code runs, but it's not creating any files in "samples" folder.

Please help!!!

"std::bad_alloc" error

when I run the command to train classifier i get the following error:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)

Same exact thing works on my vmware (ubuntu 14.04) but I wanted to run it on amazon EC2 instance as it was taking too much time on my pc (ubuntu 16.04 there). But there I get this error.. What is the problem?

unable to create .vec files with create samples file

i used below ccommand
perl bin/createsamples.pl positives.txt negatives.txt samples 5000\ "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.5 \ -maxyangle 1.5 maxzangle 0.5 -maxidev 40 -w 50 -h 50"
its working fine with python 2.7v, opencv 3.2.0
the problem was i installed with same specification in another pc. i am getting like below when i'm creating .vec samples.
positive images :2900
negative images :500

opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1676.jpg -bg tmp -vec samples/pics1676.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics2860.jpg -bg tmp -vec samples/pics2860.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics726.jpg -bg tmp -vec samples/pics726.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1090.jpg -bg tmp -vec samples/pics1090.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics2752.jpg -bg tmp -vec samples/pics2752.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics454.jpg -bg tmp -vec samples/pics454.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics498.jpg -bg tmp -vec samples/pics498.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics2183.jpg -bg tmp -vec samples/pics2183.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1130.jpg -bg tmp -vec samples/pics1130.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1493.jpg -bg tmp -vec samples/pics1493.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics766.jpg -bg tmp -vec samples/pics766.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1553.jpg -bg tmp -vec samples/pics1553.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics2287.jpg -bg tmp -vec samples/pics2287.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1060.jpg -bg tmp -vec samples/pics1060.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1814.jpg -bg tmp -vec samples/pics1814.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics0.jpg -bg tmp -vec samples/pics0.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1546.jpg -bg tmp -vec samples/pics1546.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1169.jpg -bg tmp -vec samples/pics1169.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics2443.jpg -bg tmp -vec samples/pics2443.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics496.jpg -bg tmp -vec samples/pics496.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1749.jpg -bg tmp -vec samples/pics1749.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics1519.jpg -bg tmp -vec samples/pics1519.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics402.jpg -bg tmp -vec samples/pics402.jpg.vec -num 0
opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1 -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40 -img ./positive_images/pics133.jpg -bg tmp -vec samples/pics133.jpg.vec -num 0

please let me what the problem here and why?
thanks in advance

Problem with library llibtbb.dylib (again)

I realize that there is already a closed issue pertaining to this subject, but I am really stuck. I ran:

g++ `pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/'`\
  -I. -o mergevec mergevec.cpp\
  cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp\
  cvhaartraining.cpp\
  -lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect

But I get the following error in terminal:

clang: error: no such file or directory: 'mergevec.cpp'

I've already gone through most of your awesome tutorial, but things start to fail for me at the end when I run,

./build_all.sh

All I get is:

compiling contours.c
ld: library not found for -llibtbb.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiling convert_cascade.c
ld: library not found for -llibtbb.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiling delaunay.c
ld: library not found for -llibtbb.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiling fback_c.c
ld: library not found for -llibtbb.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiling morphology.c
ld: library not found for -llibtbb.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiling motempl.c
...

All the resources that I've found online have not yet worked for me. Any advice you could give would be greatly appreciated!

Missed cvsampleoutput.cpp in step six

It should be

g++ `pkg-config --libs --cflags opencv` -I. -o mergevec mergevec.cpp  cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp  cvhaartraining.cpp  cvsamplesoutput.cpp -lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect

Needed to include cvsamplesoutput.cpp in step 6

I was initially receiving cvhaartraining.cpp:(.text+0xafd5): undefined reference to 'IOutput::createOutput(char const*, IOutput::OutputType)' during step 6. In order to compile mergevec, I needed to use the following command:

g++ pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/' -I. -o mergevec mergevec.cpp cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp cvhaartraining.cpp cvsamplesoutput.cpp -lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect

I think someone else ran into this issue on Stackoverflow as well.

I got Error during training : Bad argument

Hello mrnugget
I use this command for haar training :
opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 15 -minHitRate 0.995 -maxFalseAlarmRate 0.5 -numPos 700 -numNeg 301 -w 200 -h 100 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024 -featureType LBP

and i got this error:

 ===== TRAINING 0-stage =====
<BEGIN
POS current samples: OpenCV 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 /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp, line 162
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/apps/traincascade/imagestorage.cpp:162: 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)524

Please advice. Thank you.

how createsamples.pl will works?

i need to know that how this perl scripting making vector files taking +ves over -ve bankground images? as a aspirant i want know this concepts with in depth details if any one could find any information on this haar cascade classifier please us know.
share with us our team aspirants were always waiting for any details.
thanks in advance.

Training can't happen

When I run the seventh step,the system told that “ Training parameters are loaded from the parameter file in data folder! Please empty the data folder if you want to use your own set of parameters.”.
Can you give me some advice?

not able to create final classifier

cd /opencv-2.4.9/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="
/finished_classifier.xml" this command is not executed successfully
on REDHAT ..

no vec files

HI man,im new in opencv and i used this code perl bin/createsamples.pl positives.txt negatives.txt samples 1500\ "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\ -maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 it was successful but i didnt see any vec files inside sample folder.

inside my positives.txt
./positive_images/lettuce9.jpg
./positive_images/lettuce6.jpg
./positive_images/lettuce8.jpg
./positive_images/lettuce1.jpg
./positive_images/lettuce7.jpg
./positive_images/lettuce10.jpg
./positive_images/lettuce2.jpg
./positive_images/lettuce5.jpg
./positive_images/lettuce3.jpg

inside my negatives.txt

./negative_images/negative7.jpg
./negative_images/negative3.jpg
./negative_images/negative2.jpg
./negative_images/negative4.jpg
./negative_images/negative1.jpg
./negative_images/negative6.jpg
./negative_images/negative5.jpg

Thanks in advance

hi, i'm getting like this while creating my own harr-cascade classifier, please let me correct if anything wrong, and please tell the reason for why classifier cant be trained? and thanks in advance

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\

-numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000
-numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024
-precalcIdxBufSize 1024
PARAMETERS:
cascadeDirName: classifier
vecFileName: samples.vec
bgFileName: negatives.txt
numPos: 1000
numNeg: 600
numStages: 20
precalcValBufSize[Mb] : 1024
precalcIdxBufSize[Mb] : 1024
acceptanceRatioBreakValue : -1
stageType: BOOST
featureType: HAAR
sampleWidth: 80
sampleHeight: 40
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: ALL
Number of unique features given windowSize [80,40] : 7767622

===== TRAINING 0-stage =====
<BEGIN
POS current samples: 85
POS count : consumed 1000 : 1000
Train dataset for temp stage can not be filled. Branch training terminated.
Cascade classifier can't be trained. Check the used training parameters.

opencv_traincascade assertion error

The vec file is merged now, but when I execute

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024

it says

OpenCV Error: Assertion failed (_img.rows * _img.cols == vecSize) in CvCascadeImageReader::PosReader::get, file C:\builds\2_4_PackSlave-win64-vc12-shared\opencv\apps\traincascade\imagestorage.cpp, line 157

I can't seem to resolve the problem. I use opencv version 2.4.9 as stated in the tutorial, python 3.6 (but had to use 2.7 to execute mergevec)
Can anyone help me?

sh: 1: Syntax error: Unterminated quoted string

when I run: perl bin/createsamples.pl positives.txt negatives.txt samples 1500 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 20 -h 20"

opencv_createsamples not creating anything inside the 'samples' folder

Hi there!

when I run the command:

perl bin/createsamples.pl positives.txt negatives.txt samples 1500
"opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"

it doesn't create anything inside the 'samples' directory. I attach a screen capture showing it:
captura de pantalla 2016-02-05 a les 12 39 02

Am I doing something wrong?

Thanks a lot!! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.