Train Dataset to XML file for Cascade Classifier OpenCV

Fary Host
Fary Host
Feb 26, 2018 · 2 min read

Find image for train :

  1. open web site 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 . change value of neg_images_link.

script to download image from urls

4. run script

How to train :

  1. down load
  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
    perl bin/ 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
    python ./tools/ -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:


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store