Train Dataset to XML file for Cascade Classifier OpenCV

Find image for train :

  1. open web site http://image-net.org/ and search interest image.

2. Download url of chicken image.

3. after click download url . you see ->

3. copy top link to line 12 of resize.py . change value of neg_images_link.

script to download image from urls

4. run script resize.py
python resize.py

How to train :

  1. down load https://github.com/spmallick/opencv-haar-classifier-training
  2. find your positive image and put in the positive folder
  3. find your negative image and put in the negative folder
  4. create name list of positive image and negative image by :
    find ./positive_images -iname "*.jpg" > positives.txt
     find ./negative_images -iname "*.jpg" > negatives.txt
  5. create file samples .vec of positive image by use createsamples.pl
    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. run script merge file samples .vec by use mergevec.py
    python ./tools/mergevec.py -v samples/ -o samples.vec
  7. Start training 
    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

References & Links:

  1. https://github.com/spmallick/opencv-haar-classifier-training
  2. https://playelek.com/haar-cascade-create/