Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Save detected eyes in form of images

I have been working on eye detection and I want to detect and then extract the eyes from video feed at specific interval. I want to store the detected eyes in form of images. I have done the detection of eyes using haar cascade. Now I just want to store the detected eyes in form of images. Can anyone tell me what I can do to for the problem ? The detection code is as follows

include<stdio.h>

include<math.h>

include<opencv\cv.h>

include<opencv\highgui.h>

include<opencv2\objdetect\objdetect.hpp>

include<opencv2\highgui\highgui.hpp>

include<opencv2\imgproc\imgproc.hpp>

include<vector>

using namespace std; using namespace cv;

int main() { CascadeClassifier face, eye; if(!face.load("C:\HAAR\haarcascade_frontalcatface.xml")){

    printf("Error Loading Face Cascade");
        return -1;
}

    if(!eye.load("C:\\HAAR\\haarcascade_eye_tree_eyeglasses.xml")){

    printf("Error Loading Eye Cascade");
        return -1;
} 
    VideoCapture capture(0);
    if(!capture.isOpened())
    {

        printf("Error opening Video Stream");
        return -1;
    }

    Mat capimg,greyimg;
    vector<Rect> faces,eyes;

    while(1)
    {

        capture>>capimg;
        waitKey(10);            
            cvtColor(capimg, greyimg, CV_BGR2GRAY);
            cv::equalizeHist(greyimg,greyimg);
        face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));

        for(int i=0; i < faces.size(); i++)
        {

            Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height);
            Point pt2(faces[i].x,faces[i].y);
            Mat faceroi=greyimg(faces[i]);
            eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30));
            for(size_t j=0; j<eyes.size(); j++)
            {

                Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5,faces[i].y+eyes[j].y+eyes[j].height*0.5);
                int radius = cvRound((eyes[j].width+eyes[j].height)*0.25);
                circle(capimg, center, radius, Scalar(255,0,0),2,8,0);
            }
            rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0);
        }
        imshow("Result",capimg);
        waitKey(3);
        char c= waitKey(3);
        if (c==27)
        break;

    }
return 0;

}

Save detected eyes in form of images

I have been working on eye detection and I want to detect and then extract the eyes from video feed at specific interval. I want to store the detected eyes in form of images. I have done the detection of eyes using haar cascade. Now I just want to store the detected eyes in form of images. Can anyone tell me what I can do to for the problem ? The detection code is as follows

include<stdio.h>

include<math.h>

include<opencv\cv.h>

include<opencv\highgui.h>

include<opencv2\objdetect\objdetect.hpp>

include<opencv2\highgui\highgui.hpp>

include<opencv2\imgproc\imgproc.hpp>

include<vector>

using namespace std; using namespace cv;

int main()

{ CascadeClassifier face, eye; if(!face.load("C:\HAAR\haarcascade_frontalcatface.xml")){

    printf("Error Loading Face Cascade");
        return -1;
}

    if(!eye.load("C:\\HAAR\\haarcascade_eye_tree_eyeglasses.xml")){

    printf("Error Loading Eye Cascade");
        return -1;
} 
    VideoCapture capture(0);
    if(!capture.isOpened())
    {

        printf("Error opening Video Stream");
        return -1;
    }

    Mat capimg,greyimg;
    vector<Rect> faces,eyes;

    while(1)
    {

        capture>>capimg;
        waitKey(10);            
            cvtColor(capimg, greyimg, CV_BGR2GRAY);
            cv::equalizeHist(greyimg,greyimg);
        face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));

        for(int i=0; i < faces.size(); i++)
        {

            Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height);
            Point pt2(faces[i].x,faces[i].y);
            Mat faceroi=greyimg(faces[i]);
            eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30));
            for(size_t j=0; j<eyes.size(); j++)
            {

                Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5,faces[i].y+eyes[j].y+eyes[j].height*0.5);
                int radius = cvRound((eyes[j].width+eyes[j].height)*0.25);
                circle(capimg, center, radius, Scalar(255,0,0),2,8,0);
            }
            rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0);
        }
        imshow("Result",capimg);
        waitKey(3);
        char c= waitKey(3);
        if (c==27)
        break;

    }
return 0;

}

Save detected eyes in form of images

I have been working on eye detection and I want to detect and then extract the eyes from video feed at specific interval. I want to store the detected eyes in form of images. I have done the detection of eyes using haar cascade. Now I just want to store the detected eyes in form of images. Can anyone tell me what I can do to for the problem ? The detection code is as follows


int main()

{ CascadeClassifier face, eye; if(!face.load("C:\HAAR\haarcascade_frontalcatface.xml")){

    printf("Error Loading Face Cascade");
        return -1;
}

    if(!eye.load("C:\\HAAR\\haarcascade_eye_tree_eyeglasses.xml")){

    printf("Error Loading Eye Cascade");
        return -1;
} 
    VideoCapture capture(0);
    if(!capture.isOpened())
    {

        printf("Error opening Video Stream");
        return -1;
    }

    Mat capimg,greyimg;
    vector<Rect> faces,eyes;

    while(1)
    {

        capture>>capimg;
        waitKey(10);            
            cvtColor(capimg, greyimg, CV_BGR2GRAY);
            cv::equalizeHist(greyimg,greyimg);
        face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));

        for(int i=0; i < faces.size(); i++)
        {

            Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height);
            Point pt2(faces[i].x,faces[i].y);
            Mat faceroi=greyimg(faces[i]);
            eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30));
            for(size_t j=0; j<eyes.size(); j++)
            {

                Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5,faces[i].y+eyes[j].y+eyes[j].height*0.5);
                int radius = cvRound((eyes[j].width+eyes[j].height)*0.25);
                circle(capimg, center, radius, Scalar(255,0,0),2,8,0);
            }
            rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0);
        }
        imshow("Result",capimg);
        waitKey(3);
        char c= waitKey(3);
        if (c==27)
        break;

    }
return 0;

}


click to hide/show revision 4
No.4 Revision

Save detected eyes in form of images

I have been working on eye detection and I want to detect and then extract the eyes from video feed at specific interval. I want to store the detected eyes in form of images. I have done the detection of eyes using haar cascade. Now I just want to store the detected eyes in form of images. Can anyone tell me what I can do to for the problem ? The detection code is as follows


int main()

{ CascadeClassifier face, eye; if(!face.load("C:\HAAR\haarcascade_frontalcatface.xml")){

if(!face.load("C:\\HAAR\\haarcascade_frontalcatface.xml")){

    printf("Error Loading Face Cascade");
        return -1;
}

    if(!eye.load("C:\\HAAR\\haarcascade_eye_tree_eyeglasses.xml")){

    printf("Error Loading Eye Cascade");
        return -1;
} 
    VideoCapture capture(0);
    if(!capture.isOpened())
    {

        printf("Error opening Video Stream");
        return -1;
    }

    Mat capimg,greyimg;
    vector<Rect> faces,eyes;

    while(1)
    {

        capture>>capimg;
        waitKey(10);            
            cvtColor(capimg, greyimg, CV_BGR2GRAY);
            cv::equalizeHist(greyimg,greyimg);
        face.detectMultiScale(greyimg, faces, 1.1, 10, CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(300,300));

        for(int i=0; i < faces.size(); i++)
        {

            Point pt1(faces[i].x+faces[i].width,faces[i].y+faces[i].height);
            Point pt2(faces[i].x,faces[i].y);
            Mat faceroi=greyimg(faces[i]);
            eye.detectMultiScale(faceroi, eyes,1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30,30));
            for(size_t j=0; j<eyes.size(); j++)
            {

                Point center(faces[i].x+eyes[j].x+eyes[j].width*0.5,faces[i].y+eyes[j].y+eyes[j].height*0.5);
                int radius = cvRound((eyes[j].width+eyes[j].height)*0.25);
                circle(capimg, center, radius, Scalar(255,0,0),2,8,0);
            }
            rectangle(capimg, pt1, pt2, cvScalar(0,255,0),2,8,0);
        }
        imshow("Result",capimg);
        waitKey(3);
        char c= waitKey(3);
        if (c==27)
        break;

    }
return 0;

}