Ask Your Question

Revision history [back]

Face Recoginition - Process is very slow if images from camera doesn't contain face.

I have used face cascade to tracking face through webcame. And loop function is very fast if image from camera contains face. However, if not, it is very slow.

My source:

void camera() {
String face_cascade_name = "haarcascade_frontalface_alt.xml";
String eye_cascade_name = "haarcascade_eye.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
String window_name = "Capture - Face detection";
VideoCapture cap(0);
if (!face_cascade.load(face_cascade_name)) {
    printf("--(!)Error loading\n");
};
if (!eyes_cascade.load(eye_cascade_name)) {
    printf("--(!)Error loading\n");
};
if (!cap.isOpened()) {
    cerr << "Capture Device ID " << 0 << "cannot be opened." << endl;
} else {
    Mat frame;
    vector<Rect> faces;
    vector<Rect> eyes;
    for (;;) {
            cap.read(frame);
        Mat original = frame.clone();
        Mat frame_gray;
        cvtColor(original, frame_gray, CV_BGR2GRAY);
        equalizeHist(frame_gray, frame_gray);
        face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2,
                CASCADE_FIND_BIGGEST_OBJECT | CASCADE_DO_ROUGH_SEARCH,
                Size(30, 30));
        if (faces.size() > 0) {
            rectangle(original, faces[0], Scalar(0, 0, 255), 2, 8, 0);
            Mat face = frame_gray(faces[0]);
            eyes_cascade.detectMultiScale(face, eyes, 1.1, 2,
                    0 | CASCADE_SCALE_IMAGE, Size(30, 30));
            Mat veFace = original(faces[0]);
            for (int i = 0; i < eyes.size(); i++) {
                rectangle(veFace, eyes[i], Scalar(255, 0, 255), 2, 8, 0);
            }
            namedWindow(window_name, CV_WINDOW_AUTOSIZE);
            imshow(window_name, original);
        }
        if (waitKey(30) == 27) {
            cout << "esc key is pressed by user" << endl;
            break;
        }
    }
}}

How can i produce that time, please help me.

Face Recoginition - Process is very slow if images from camera doesn't contain face.

I have used face cascade to tracking face through webcame. And loop function is very fast if image from camera contains face. However, if not, it is very slow. Please help.

My source:

void camera() {
String face_cascade_name = "haarcascade_frontalface_alt.xml";
String eye_cascade_name = "haarcascade_eye.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
String window_name = "Capture - Face detection";
VideoCapture cap(0);
if (!face_cascade.load(face_cascade_name)) {
    printf("--(!)Error loading\n");
};
if (!eyes_cascade.load(eye_cascade_name)) {
    printf("--(!)Error loading\n");
};
if (!cap.isOpened()) {
    cerr << "Capture Device ID " << 0 << "cannot be opened." << endl;
} else {
    Mat frame;
    vector<Rect> faces;
    vector<Rect> eyes;
    for (;;) {
            cap.read(frame);
        Mat original = frame.clone();
        Mat frame_gray;
        cvtColor(original, frame_gray, CV_BGR2GRAY);
        equalizeHist(frame_gray, frame_gray);
        face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2,
                CASCADE_FIND_BIGGEST_OBJECT | CASCADE_DO_ROUGH_SEARCH,
                Size(30, 30));
        if (faces.size() > 0) {
            rectangle(original, faces[0], Scalar(0, 0, 255), 2, 8, 0);
            Mat face = frame_gray(faces[0]);
            eyes_cascade.detectMultiScale(face, eyes, 1.1, 2,
                    0 | CASCADE_SCALE_IMAGE, Size(30, 30));
            Mat veFace = original(faces[0]);
            for (int i = 0; i < eyes.size(); i++) {
                rectangle(veFace, eyes[i], Scalar(255, 0, 255), 2, 8, 0);
            }
            namedWindow(window_name, CV_WINDOW_AUTOSIZE);
            imshow(window_name, original);
        }
        if (waitKey(30) == 27) {
            cout << "esc key is pressed by user" << endl;
            break;
        }
    }
}}

How can i produce that time, please help me.

Face Recoginition - Process is very slow if images from camera doesn't contain face.

I have used face cascade to tracking face through webcame. And loop function is very fast if image from camera contains face. However, if not, it is very slow. Please help.

My source:

void camera() {
String face_cascade_name = "haarcascade_frontalface_alt.xml";
String eye_cascade_name = "haarcascade_eye.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
String window_name = "Capture - Face detection";
VideoCapture cap(0);
if (!face_cascade.load(face_cascade_name)) {
    printf("--(!)Error loading\n");
};
if (!eyes_cascade.load(eye_cascade_name)) {
    printf("--(!)Error loading\n");
};
if (!cap.isOpened()) {
    cerr << "Capture Device ID " << 0 << "cannot be opened." << endl;
} else {
    Mat frame;
    vector<Rect> faces;
    vector<Rect> eyes;
    for (;;) {
            cap.read(frame);
        Mat original = frame.clone();
        Mat frame_gray;
        cvtColor(original, frame_gray, CV_BGR2GRAY);
        equalizeHist(frame_gray, frame_gray);
        face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2,
                CASCADE_FIND_BIGGEST_OBJECT | CASCADE_DO_ROUGH_SEARCH,
                Size(30, 30));
        if (faces.size() > 0) {
            rectangle(original, faces[0], Scalar(0, 0, 255), 2, 8, 0);
            Mat face = frame_gray(faces[0]);
            eyes_cascade.detectMultiScale(face, eyes, 1.1, 2,
                    0 | CASCADE_SCALE_IMAGE, Size(30, 30));
            Mat veFace = original(faces[0]);
            for (int i = 0; i < eyes.size(); i++) {
                rectangle(veFace, eyes[i], Scalar(255, 0, 255), 2, 8, 0);
            }
            namedWindow(window_name, CV_WINDOW_AUTOSIZE);
            imshow(window_name, original);
        }
        if (waitKey(30) == 27) {
            cout << "esc key is pressed by user" << endl;
            break;
        }
    }
}}

How can i produce that time, please help me.