Why create your own Haar-classifier cascades?

前端 未结 2 698
梦如初夏
梦如初夏 2021-02-01 09:07

I found this tutorial on creating your own haar-classifier cascades.

This raised the question with me: what are the advantages, if any, of running HaarTraining, and crea

2条回答
  •  独厮守ぢ
    2021-02-01 09:15

    I can give you a Linux example. The code and techniques were pulled from a variety of sources. It follows this example but with a python version of mergevec, so you don't have to compile the mergevec.cpp file.

    Assuming that you have two folders with cropped & ready positive & negative images (.png files in this example), you create two text files with all the image names in:

    find positive_images -iname "*.png" > positives.txt
    find negative_images -iname "*.png" > negatives.txt
    

    Then, using the createsamples.pl script provided by Naotoshi Seo (in the OpenCV/bin folder), which takes the two text files and an output folder, and creates the .vec files:

    perl createsamples.pl positives.txt negatives.txt 'output' 1500 "opencv_createsamples -bgcolor 0 -bgthresh 0 -maxzangle 0.5 -w 50 -h 50"
    

    Follow that with a python script created by Blake Wulfe called mergevec.py, which will create an output.vec file by combining all the .vec files in the subfolder

    python mergevec.py -v samples -o output.vec
    

    Assuming that is all done, using opencv_traincascade as follows should help:

    opencv_traincascade -data classifier -vec output.vec -bg negatives.txt \
      -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 200 \
      -numNeg 400 -w 50 -h 50 -mode ALL
    

    If all that goes well, use your newly created cascade (classifier/cascade.xml) with something like facedetect.py from opencv samples:

    opencv-3.0.0-rc1/samples/python2/facedetect.py --cascade classifier/cascade.xml test_movie.mp4
    

提交回复
热议问题