Training of Opencv-haar facial features

Source: Internet
Author: User

Step 1: Put positive samples, negative samples, opencv_createsamples,opencv_haartraining into a folder below, to facilitate the operation behind.
Step 2: Generate a profile for positive and negative samples

Positive Sample Description file
Find Positive_boosted-iname "*.bmp"-exec Echo \{\} 1 0 0 20 20 \; >
Positive_boosted/face00244.bmp 1 0 0 20 20
Positive_boosted/face00177.bmp 1 0 0 20 20
Positive_boosted/face01533.bmp 1 0 0 20 20
Positive_boosted/face01542.bmp 1 0 0 20 20
Positive_boosted/face00733.bmp 1 0 0 20 20
Positive_boosted/face01708.bmp 1 0 0 20 20
Positive_boosted/face01625.bmp 1 0 0 20 20

The pos_image/is the relative pathname, followed by the file name, 1 for a file, 0 0 24 24 for the file's 2 vertex position coordinates. Save Exit is OK.

Negative Sample Description file
Find Negative_boosted-iname *.bmp > Non_face.txt

Step 3: Generate VEC files
Opencv_createsamples-vec face.vec-info face.txt-bg non_face.txt-w 20-h 20-num 2429
The-vec is to specify the file name of the following output VEC file,-info Specify a positive sample description file,-BG Specify a negative sample description file, W and H respectively, the width and height of the sample,-num indicates the number of positive samples. After executing the command, a Face.vec file is produced in the current directory.

Step 4: Start training
Create a new XML folder in the current directory to hold the generated. xml file.
Opencv_haartraining-data Xml-vec face.vec-bg non_face.txt-npos 500-nneg 500-w 20-h 20-nstages 20-nsplits 2-minh Itrate 0.999-maxfalsealarm 0.5

Opencv_traincascade (New command)
-data is the location of the output XML intermediate file;
-vec Positive Sample file name
-BG Negative Sample file name
-nsplits 1 means using a simple stump classfier classification.
-mode (Default|all) All means that the type of Haar is used in both vertical and angular rotation of 45 degrees; The default is just vertical.
-npos Number of positive samples
-nneg Negative Sample
-minhitrate minimum hit ratio, which is the accuracy of the training target.
-maxfalsealarm Maximum false alarm (false detection rate), each layer of training to this value less than 0.5 when the end of training, into the next level of training

In the actual training, in order to save time, adjust the small Npos,nneg

Generates a xml.xml file that can be tested using the resulting classifier.

Step 5: Merging the XML files generated by the training
Generate multiple

Training of Opencv-haar facial features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.