Training a haar cascade classifier in opencv 3
This is hard... this is very hard! But I did.
So. first you must have installed the OpenCV on your machine. After, install the dependency:
sudo apt-get install libopencv-dev
Ok. Now, create the training files.
Positive training file
The positive training file must have the following structure:
/home/complete/path/to/image.png 1 x y h w
Where: - 1: number of Bounding boxes in the image - x: x coordenate - y: y coordenate - w: pixel width - h: pixel height
Negative training file
This is easier, just place each file in a line. You can do this in bash:
find neg -iname "negative/path/*" > bg.txt
Creating the vector file
You need to create a vector file of positive images. This file must contain all of your positive examples:
opencv_createsamples -info postive.txt -vec pos.vec -num 775 -w 64 -h 64
Where: - -info: the file containing the positive images: - -vec``: output vector file --num: # of positive samples --w: image width --h``:: image height
Starting traning
Now time to start the training. Execute the following line:
opencv_traincascade -data model -vec pos.vec -bg negative.txt -w 64 -h 64 -numPos 599 -numNeg 599 -precalcValBufSize 4048 -precalcIdxBufSize 4048 -numStages 5
Where: - -data``: output directory. not that the directory must exists already --vec: the vector file that was just created --bg: the negative images file - `-w`: image width - `-h: image height - -numPos``: # of positive images. Note that this number must be equal or lower to the negative number of images --numNeg``: # of negative images - -numStages: # of training iteractions
Done moderfocker!











