Analysis of openCV’s face detection – the sample, method and performance

show-off-your-eye-colour-0 -picture from

opencv face detection

From the picture of face detection in openCV website…

This post is the first of series articles discussing openCV HAAR classifier training and use, as it was implemented in GSoc 2012 project. Here in this post there is no complex algorithms presented, instead, this focuses on requirements and techniques for successful classifier training using openCV.

Samples used in openCV face detection

3,000 negative pictures, 5,000 positive frontal face pictures were used and resulted in openCV’s good accuracy of face detection. These 5k pictures were from 1,000 individuals. Put aside how difficult it was to collect so many pictures (which I will talk about in another post), this number is believed to be able to achieve satisfied results due to the fact that the most common features should be covered, such like the dark eyes, bright nose and the relative positions amongst these parts. Special features, such like the colours of eyes, the height of nose and the width of face cheeks, are less worthy of training.

show-off-your-eye-colour-0 -picture from

Downloads of face samples, as mentioned in Naotoshi’s tutorials, can be referred in

How these samples were used

openCV never told how these samples were used. As openCV only provides xml files, the only thing clear is how many stages used in the training with these samples. Neither were the cropping of pictures nor ultimate picture sizes provided. As far as concerned,

Kuranov et. al. [3] states as 20×20 of sample size achieved the highest hit rate. Furthermore, they states as “For 18×18 four split nodes performed best, while for 20×20 two nodes were slightly better. Thus, -w 20 -h 20 would be good

And, how the picture cropping affects the quality of training will be discussed in a later post.

Method of training

To save some words, the detailed procedures of sample training as well as parameter introductions please refer to Naotoshi’s tutorial. Here I introduce .bat files used in my training. These files save good time to deal with command lines.


cd dir
opencv_createsamples.exe -info ./contract_palm4/filelist.dat -vec ./contract_palm4/output.vec -num 7430 -bg ./neg3/filelist.dat -bgcolor 0 -w 20 -h 20


echo “haartraining in progress…”
cd opencv_haartraining.exe -data
./contract_palm4/haarcascade -vec
./contract_palm4/output.vec -bg ./neg3/filelist.dat -nstages 20 -nsplits 2 -minhitrate 0.999 -maxfalsealarm 0.0005 -weighttrimming = 0.95 -npos 7430 -nneg 4300 -w 20 -h 20 -mem 1024 -nonsym -mode ALL

and, cascadeconvert.bat (opencv_cascadeconvert.exe is not included in openCV installation)

cd opencv_cascadeconvert.exe –size=”20×20″
./contract_palm4/haarcascade ./contract_palm4/haarcascade/CP04.xml

Author: Andol Li

A HCI researcher, a digital media lecturer, an information product designer, and a python/php/java coder.

Leave a comment
Due to technical adjustments, the comment function is shortly closed and will be re-openning soon. Thanks.

Copyrights 2006-2017 © All rights reserved
Theme Tree2, re-designed by Andol Li, powered by WordPress and Bootsrap
WWW.ANDOL.ME | 浙ICP备15040508号-1
公安备案图标 浙公网安备33010602004018号
Back to top