Skip to content

Commit

Permalink
Update face_eye_detection_sample.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sturkmen72 committed Dec 30, 2015
1 parent ac6e0d1 commit 41f1cb9
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions face_eye_detection_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ const char *eyeCascadeFilename2 = "haarcascade_mcs_lefteye.xml"; // Basic eye de

const char *windowName = "WebcamFaceRec"; // Name shown in the GUI window.

#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
#include "detectObject.h"

#include "opencv2/opencv.hpp"

Expand Down Expand Up @@ -118,7 +116,7 @@ void detectLargestObject(const Mat &img, CascadeClassifier &cascade, Rect &large

}

void initDetectors(CascadeClassifier &faceCascade, CascadeClassifier &eyeCascade2)
void initDetectors(CascadeClassifier &faceCascade, CascadeClassifier &eyeCascade1, CascadeClassifier &eyeCascade2)
{
// Load the Face Detection cascade classifier xml file.
try // Surround the OpenCV call by a try/catch block so we can give a useful error message!
Expand All @@ -137,6 +135,19 @@ void initDetectors(CascadeClassifier &faceCascade, CascadeClassifier &eyeCascade
// Load the Eye Detection cascade classifier xml file.


try // Surround the OpenCV call by a try/catch block so we can give a useful error message!
{
eyeCascade1.load(eyeCascadeFilename1);
}
catch (cv::Exception &e) {}
if (eyeCascade1.empty())
{
cerr << "ERROR: Could not load 1st Eye Detection cascade classifier [" << eyeCascadeFilename1<< "]!" << endl;
cerr << "Copy the file from your OpenCV data folder (eg: 'C:\\OpenCV\\data\\haarcascades') into this WebcamFaceRec folder." << endl;
exit(1);
}
cout << "Loaded the 1st Eye Detection cascade classifier [" << eyeCascadeFilename1 << "]." << endl;

try // Surround the OpenCV call by a try/catch block so we can give a useful error message!
{
eyeCascade2.load(eyeCascadeFilename2);
Expand All @@ -148,9 +159,7 @@ void initDetectors(CascadeClassifier &faceCascade, CascadeClassifier &eyeCascade
cerr << "Copy the file from your OpenCV data folder (eg: 'C:\\OpenCV\\data\\haarcascades') into this WebcamFaceRec folder." << endl;
exit(1);
}
cout << "Loaded the 1st Eye Detection cascade classifier [" << eyeCascadeFilename2 << "]." << endl;


cout << "Loaded the 2nd Eye Detection cascade classifier [" << eyeCascadeFilename2 << "]." << endl;


}
Expand Down Expand Up @@ -303,7 +312,7 @@ int main()
CascadeClassifier eyeCascade2;

Rect faceRect;
VideoCapture videoCapture("n.mp4");
VideoCapture videoCapture( 0 );



Expand All @@ -312,14 +321,14 @@ int main()
cout << "Compiled with OpenCV version " << CV_VERSION << endl << endl;

// Load the face and 1 or 2 eye detection XML classifiers.
initDetectors(faceCascade, eyeCascade2);
initDetectors(faceCascade, eyeCascade1, eyeCascade2);

Mat thresh, gray;
while (1)
{
Mat frame;
videoCapture >> frame;
detectLargestObject(frame, faceCascade, faceRect);
detectLargestObject(frame, faceCascade, faceRect, frame.cols);
if (faceRect.width > 0)
{
// modification is begin here
Expand Down

0 comments on commit 41f1cb9

Please sign in to comment.