OpenCV Cascade Classifier Training

By | August 14, 2015


This training is based on three stages and i listed all possible steps below.

  1. Downloading Tools and preparation :
    • Download and install openCV . It provides important tools for image preparation and training. Download from here and for installation steps visit my previous article from here
    • Download Haar Training material from here. Very useful tools and utilities for image preparation
    • Organize your +ve (must contains object you want to recognize and for complex object number of images must be more than 1000) and -ve images (at least 2000 / more) also known as background or samples images
  2. Training :
    • In my case i collected 1000 +ve images containing object and 2000 –ve images (without object).
    • List all –ve files in a neg.txt document. if your data set is big,  you can use DOS commands to list all images in txt file
    • in my case my working directory is e:/opencv/development/images. Go into your working directory and run DOS command
    • To add full path for each -ve image name. create batch file as given below
      • Run your batch file and it will create a negNew.txt file with full path of -ve images
    • Next step is to crop +ve images using Objectmake.exe and create an info.txt file
        • Copy step2 from downloaded folder to your working directory. Put all +ve files in your rawdata directory. Simply execute Objectmake.exe file and start marking object of your interest in your +ve images
        • Once you are done with this step. Move info.txt file to your working directory home.
        • Now add absolute path for each +ve image in info.txt.

    • Generated Vector file using createSample classic tool of OpenCV
        • create batch file and execute it. Batch file contains following command

      • you can change parameters according to your requirement
    • Verify vector file and browsed all cropped images

      • if your vector file is correctly created. it will display all cropped images one by one
    • Initiate a Haar Cascade Classifier training to get cascade.xml trained file and is generated successfully. It takes lot of time depends upon your data set. To initiate this process create batch file with following command
        • create classifier directory in your working folder

      • You will get cascade.xml file which is available in classifier directory. You can delete all other file. They are not required.
  3. Detection :
    1. Use opencv code for object detection. Have a look at code. Code is taken from the openCV tutorials. Check original code here

     

Useful Tutorials

  1. http://vgl-ait.org/cvwiki/doku.php?id=opencv:tutorial:haartraining
  2. http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html
  3. http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html
  4. http://www.tectute.com/2011/06/opencv-haartraining.html
  5. http://note.sonots.com/SciSoftware/haartraining.html

Watch this video for further details :