Environment

  • Python 2.7.15
  • Windows 10
  • opencv 3.4.3

Prepare Steps

  1. Clone the repository
    git clone https://github.com/mrnugget/opencv-haar-classifier-training
    
  2. Install opencv. Reference the post face detection in python using webcam
  3. Samples
    • positive sample for detect the object
    • negative sample without the object
    • How many images? 5000 is better than 1000
    • factors:
      • CPU power
      • Quality of images
      • Huge images
      • Time
      • Good samples

Experiments Steps

  1. Prepare 40 positive samples and 600 negative samples
  2. Prepare 40 positive samples. They have to differ in lighting and background.
    • Collecting these pictures from:
      • From internet
      • Extract from video
      • Scan
      • Take a picture
    • Crop pictures
  3. Resize image with FastStone Photo Resizer.
  4. Put these positive samples into the directory D:\Temp\opencv-haar-classifier-training\positive_images
  5. Write the path of image to a text file
    find ./positive_images -iname "*.jpg" > positives.txt
    

    Try the same function on Windows 10 with command:

    dir /b/s positive_images\*.jpg>positives.txt
    
  6. Prepare 600 negative samples.
    • Collecting these pictures from:
      • Extract from video
  7. Save the list of paths to a text file
    find ./negative_images -iname "*.jpg" > negatives.txt
    

Reference