OpenCV has an example of Face Detection, located in the samples directory of OpenCV distribution. It uses a type of face detector called a Haar Cascade classifier. Basically it performs a simple operation. Given an image, the face detector examine each image location and classifies it as "face" or "not face".
However, I found that the example is hard to understand. So I simplify the code and add some comments for us to better understand it. I also modify the code to take the input from webcam rather than static images.
The code below displays video from webcam, detect faces and draw a surrounding box for each face found.
Listing 1: OpenCV Face Detection
Learning OpenCV: Computer Vision with the OpenCV Library
By: Gary Bradski, Adrian Kaehler
This book is the "de facto" OpenCV User's Manual. It provides a practical, pragmatic, accessible book on computer vision, with algorithmic explanation and concrete example code snippets. Written by the creators of OpenCV, no doubt you should obtain a copy.
Machine Vision: Theory, Algorithms, Practicalities (Signal Processing and its Applications)
By: E. R. Davies
This book provides a solid and concrete foundation to computer vision from engineering point of view. Use Learning OpenCV from Gary Bradsky to learn how to use OpenCV, and use this book to understand how OpenCV works behind the screen.
C Programming Language (2nd Edition)
By: Brian W. Kernighan
For you who new to C programming, this is a must-have book for you. Written by the C creator himself, this book is concise and powerful, just like C itself.
Nash on Feb 24, 2009:
main() with this:facedetect myphoto.jpg.haarcascade_frontalface_alt.xml to the same directory with the code above. ABHAY SHANKAR on Feb 27, 2009:
Nash on Feb 27, 2009:
cvHaarDetectObjects. Maybe we can find the answers thereatzu on Mar 3, 2009:
atzu on Mar 3, 2009:
fuzy on Mar 19, 2009:
Kamardin on Apr 22, 2009:
Eak on Apr 22, 2009:
Aaron on May 14, 2009:
Nash on May 15, 2009:
Jaideep on May 15, 2009:
Nash on May 15, 2009:
felix on May 21, 2009:
Nash on May 22, 2009:
cvFlip(frame, frame, -1);cvFlip(frame, frame, 0);detectFaces(). Felix Okoye on May 22, 2009:
Nash on May 23, 2009:
sprintf() part. Maybe you have to format filename in VC++'s way. Since I don't have VC++, I cannot help you to figure it out.Gabriel on Jun 24, 2009:
capture = cvCaptureFromCAM( CV_CAP_ANY );
if( !capture ) {
fprintf( stderr, "ERROR: capture is NULL n" );
getchar();
return -1;
}Gabriel on Jun 24, 2009:
Tim on Jul 1, 2009:
Nash on Jul 1, 2009:
1.jpg, ..., n.jpg. Thanks. felix on Jul 12, 2009:
abyadh on Jul 21, 2009:
Nash on Jul 22, 2009:
Luis on Aug 20, 2009:
Nash on Aug 20, 2009:
Jason on Aug 29, 2009:
Nash on Aug 29, 2009:
C:/OpenCVC:/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xmlraj on Sep 12, 2009:
Nash on Sep 13, 2009:
Anju on Sep 14, 2009:
Nash on Sep 14, 2009:
Anju on Sep 14, 2009:
Felipe on Oct 16, 2009:
Nash on Oct 17, 2009:
watachi on Oct 30, 2009:
Tony on Nov 18, 2009:
Greg on Dec 17, 2009:
Mohamed Alkaduhimi on Jan 28, 2010:
Lideman on Feb 3, 2010:
alex on Feb 14, 2010:
john on Feb 20, 2010:
Dileep S.P on Mar 8, 2010:
Nash on Mar 9, 2010:
capture = cvCaptureFromCAM(0);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 240);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 160); askl on Mar 23, 2010:
Kit on Apr 20, 2010:
Rustam Rakhimov on Apr 22, 2010:
jasm on May 21, 2010:
Javier on May 26, 2010:
amira on Jun 3, 2010:
Nash on Jun 4, 2010:
Thumbu on Jun 4, 2010:
Shervin Emami on Jun 8, 2010:
RAVI on Jun 16, 2010:
vibin on Jun 17, 2010:
Nash on Jun 18, 2010:
Mamdouh on Jul 1, 2010:
Robert on Jul 11, 2010:
Rezaei on Oct 27, 2010:
Rezaei on Oct 27, 2010:
Nash on Oct 27, 2010:
Rezaei on Oct 27, 2010:
Rezaei on Oct 28, 2010:
Squally on Nov 2, 2010:
Rezaei on Nov 14, 2010:
Prasad on Nov 21, 2010:
Squally on Nov 25, 2010:
Abhishek on Dec 1, 2010:
| ICQ | 489571630 |
| Skype | dede_bl4ckheart |
| Yahoo | dede_bl4ckheart |
| nashruddin.amin |
Jin Le on Feb 23, 2009:
I am a beginner at openCV and i really like to try out your face dectection application... but the thing is that i having problems getting the application up and running..
when i try to compile it, there are no errors of any kind... but a cmd promt says (assertion failed) pointing on this line of code "assert( cascade && storage && capture );" i am using VS 2008 c++
please give me a pointer..
i am looking forward for your reply ...
best regards
Jin le