Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

localize the eyes using ROI

I have used face-cascade classifier and found the face and found eyes region using ROI without using eye cascade

as shown in the image Image.

Now I want to apply ROI to detect eyes region exactly from given face coordinates

how can I get this result ?

image description

This is my code for the first image :

cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
    equalizeHist(frame_gray, frame_gray);

    // Detect faces
    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 4, CASCADE_SCALE_IMAGE, Size(20, 20));

    // Set Region of Interest

    size_t i = 0; 

    for (i = 0; i < faces.size(); i++) // Iterate through all current elements (detected faces)

    {

        Point pt1(faces[i].x, faces[i].y); // Display detected faces on main window - live stream from camera
        Point pt2((faces[i].x + faces[i].height), (faces[i].y + faces[i].width));
        rectangle(frame, pt1, pt2, Scalar(0, 255, 0), 2, 8, 0);

        // set ROI for the eyes

        Rect Roi = faces[i];

        Roi.height = Roi.height / 4;

        Roi.y = Roi.y + Roi.height;

        Mat eye_region = frame(Roi).clone();

        Mat eye_gray = frame(Roi).clone();

        imshow("video main      frame", eye_region);