I created a face recognition system to do something like this using OpenCV, you can see the result here .
The method I used then consisted of two different haarTraining applications with standard built-in OpenCV classifiers. I used the haarcascade_frontalface_default.xml classifier to see if the user is viewing the screen and haarcascade_profileface.xml to see if the user is watching. The following code should help you get started with openCV and C ++.
CvHaarClassifierCascade *cascade_face; CvMemStorage *storage_face; CvHaarClassifierCascade *cascade_profile; CvMemStorage *storage_profile; //profile face storage_profile = cvCreateMemStorage( 0 ); cascade_profile = ( CvHaarClassifierCascade* )cvLoad( "haarcascade_profileface.xml", 0, 0, 0 ); cvHaarDetectObjects( frm, cascade_profile, storage_profile, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING); //frontal face storage_face = cvCreateMemStorage( 0 ); cascade_face = ( CvHaarClassifierCascade* )cvLoad( "haarcascade_frontalface_default.xml", 0, 0, 0 ); cvHaarDetectObjects( frm, cascade_face, storage_face, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING); //detect profiles CvSeq *profile = cvHaarDetectObjects(img,cascade_profile, storage_profile, 1.1,3,0,cvSize( 20, 20 )); for( i = 0 ; i < ( profile ? profile->total : 0 ) ; i++ ) { CvRect *r = ( CvRect* )cvGetSeqElem( profile, i ); //draw rectangle here, or do other stuff } //detect front CvSeq *faces = cvHaarDetectObjects(img,cascade_face, storage_face, 1.1,3,0,cvSize( 20,20 )); for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ ) { CvRect *r = ( CvRect* )cvGetSeqElem( faces, i ); //draw rectangle here, or do other stuff }
source share