Created
June 23, 2014 20:59
-
-
Save FlyingJester/c862754636e8e20b8f3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "opencv2/objdetect/objdetect.hpp" | |
| #include "opencv2/highgui/highgui.hpp" | |
| #include "opencv2/imgproc/imgproc.hpp" | |
| #include <iostream> | |
| #include <stdio.h> | |
| using namespace std; | |
| using namespace cv; | |
| /** Function Headers */ | |
| void detectAndDisplay( Mat frame, const char * ); | |
| /** Global variables */ | |
| CascadeClassifier face_cascade; | |
| RNG rng(12345); | |
| /** @function main */ | |
| int main( int argc, const char** argv ) | |
| { | |
| String face_cascade_name = argv[1]; | |
| Mat frame; | |
| if (argc < 2) { | |
| cout << "Please give file as parameter" << endl; | |
| return -1; | |
| } | |
| //-- 1. Load the cascades | |
| if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; }; | |
| frame = imread( argv[2]); | |
| //-- 3. Apply the classifier to the frame | |
| if( !frame.empty() ) | |
| { detectAndDisplay( frame, argv[3] ); } | |
| else | |
| { printf(" --(!) No image! -- Break!"); return -1; } | |
| } | |
| /** @function detectAndDisplay */ | |
| void detectAndDisplay( Mat frame , const char *aExtra) | |
| { | |
| std::vector<Rect> faces; | |
| Mat frame_gray; | |
| cvtColor( frame, frame_gray, CV_BGR2GRAY ); | |
| equalizeHist( frame_gray, frame_gray ); | |
| //-- Detect faces | |
| face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) ); | |
| for( int i = 0; i < faces.size(); i++ ) | |
| { | |
| Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 ); | |
| cout << center.x - (faces[i].width / 2) <<"," << center.y - (faces[i].height / 2) << "," << faces[i].width << "," << faces[i].height << endl; | |
| cout << aExtra << endl; | |
| ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 ); | |
| Mat faceROI = frame_gray( faces[i] ); | |
| std::vector<Rect> eyes; | |
| } | |
| cout << "###" << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment