Ask Your Question

elp14smaa's profile - activity

2015-11-20 16:08:17 -0600 received badge  Student (source)
2015-11-08 18:25:19 -0600 commented answer reduce the searching area for eye detection

Thanks @sturkmen for helping me , I have one final question . after detecting eyes using Roi ,

I converted the detected eye region to Y channel here is the code for this . Is this right method ?

for (size_t j = 0; j < eyes.size(); j++)
    {
        Rect r(Roi.x + eyes[j].x, Roi.y + eyes[j].y, eyes[j].width, eyes[j].height);


        rectangle(frame, r, Scalar(255, 0, 0), 3, 1, 0);


        Mat eye_region = frame(eyes[j]).clone();

        Mat eye_region_YCbCr;

        cvtColor(eye_region, eye_region_YCbCr, CV_BGR2YCrCb);

        vector<Mat> channels;

        split(eye_region_YCbCr, channels);

        Mat eye_region_Ychannel = channels[0].clone();

        imshow("Y", eye_region_Ychannel);

    }
}

Full code is Here

2015-11-08 08:32:59 -0600 commented answer reduce the searching area for eye detection

I used this :

Rect Roi = faces[ic];
    Roi.height = Roi.height / 4;
    Roi.y = Roi.y + Roi.height;

    cv::Mat crop = frame(Roi);
    cvtColor(crop, gray, CV_BGR2GRAY);
    imshow("ROI", gray);
    eye_cascade.detectMultiScale(gray, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(20, 20));

    for (size_t j = 0; j < eyes.size(); j++)
    {
        Rect r(faces[ic].x + eyes[j].x, faces[ic].y + eyes[j].y, eyes[j].width, eyes[j].height);

        rectangle(frame, r, Scalar(255, 0, 0), 3, 1, 0);
    }
}

The eye region is like this :Image I think is better than before ,

But when I pass it to detect eyes the eye is not detected correctly is appears on the forehead like this

Image

2015-11-08 05:17:51 -0600 commented answer reduce the searching area for eye detection

I want to pass eye region like this red rectangle area around the eyes Image

2015-11-08 04:40:40 -0600 commented answer reduce the searching area for eye detection

I have used it like this

    Rect Roi;
    Roi.x=faces[i].x;
    Roi.y=faces[i].y;
    Roi.width = (faces[i].width);
    Roi.height = (faces[i].height)/5;

    cv::Mat crop = frame(Roi);
    imshow("ROI", crop);

but the eyes are not inside this rect , it shows the forehead

this is the output : Image

2015-11-06 16:49:48 -0600 commented answer reduce the searching area for eye detection

Thanks but ,what about x,y and the width ?

2015-11-06 14:50:23 -0600 commented answer reduce the searching area for eye detection

in Mat faceROI = frame_gray( faces[i] ); the whole face is passed to eyes_cascade ,

I want to pass only the region that contains the eyes not the full face. I think this should do it ,

 cv::Rect roi(x, y, width, height);
 cv::Mat image_roi = frame(roi);

but what should be the value of my x,y, width, height

2015-11-06 08:12:37 -0600 commented question reduce the searching area for eye detection

it is not clear to me, I just want an example of how to set the ROI using rect to search for the eyes

2015-11-06 03:42:24 -0600 received badge  Enthusiast
2015-11-05 16:13:51 -0600 received badge  Editor (source)
2015-11-05 16:13:09 -0600 asked a question reduce the searching area for eye detection

I'm trying to reduce the searching area for eye detection . I have passed a rect (ROI) like this :

Rect region_of_interest = Rect(gray_img(faces[i].x),gray_img(faces[i].y) + gray_img(faces[i].height)/5,gray_img(faces[i].width), gray_img(faces[i].height)/3);
   Mat image_roi = region_of_interest;

I getting this errors and I don't know if what I'm doing is right can you help me please to do it correctly , I want to search for the eye in a rectangle area that contains the eyes not the whole face . Thanks for help

error: invalid conversion from 'int' to 'const cv::Range*' [-fpermissive]|
error: no matching function for call to 'cv::Rect_<int>::Rect_(cv::Mat, cv::MatExpr, cv::Mat, cv::MatExpr)
error: conversion from 'cv::Rect' to non-scalar type 'cv::Mat' requested|

The full function is :

  Mat cap_img,gray_img;
  vector<Rect> faces, eyes;
  while(1)
{
capture >> cap_img;
waitKey(10);
cvtColor(cap_img, gray_img, CV_BGR2GRAY);
cv::equalizeHist(gray_img,gray_img);
face_cascade.detectMultiScale(gray_img, 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);

   Rect region_of_interest = Rect(gray_img(faces[i].x),gray_img(faces[i].y) + gray_img(faces[i].height)/5,gray_img(faces[i].width), gray_img(faces[i].height)/3);
   Mat image_roi = region_of_interest;

    eye_cascade.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);
        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(cap_img, center, radius, Scalar(255,0,0), 2, 8, 0);
    }
    rectangle(cap_img, pt1, pt2, cvScalar(0,255,0), 2, 8, 0);
}
2015-10-30 16:32:02 -0600 commented question face and eye detection not showing detection result

I don't think waitKey() is the problem because the above is a function called in main()

    int main( void )

  {

CvCapture* capture;
Mat frame;

//-- 1. Load the cascade
 CascadeClassifier face_cascade;
face_cascade.load( "haarcascade_frontalface_alt2.xml" );
CascadeClassifier eye_cascade;
 eyes_cascade.load( "haarcascade_eye.xml" );



//-- 2. Read the video stream
capture = cvCaptureFromCAM( 0 );
if( capture )
{
    for(;;)
    {
        frame = cvQueryFrame( capture );

        //-- 3. Apply the classifier to the frame
        if( !frame.empty() )
        { detectAndDisplay( frame ); }
        else
        { printf(" --(!) No captured frame -- Break!"); break; }

        int c = waitKey(10);
        if( (char)c == 'c' ) { break; }

    }
}
return 0;

   }
2015-10-30 13:30:25 -0600 asked a question face and eye detection not showing detection result

Hi

I have written this code to detect eye and face ,but it is not detecting eye or face when I run the code

void isplay( Mat frame )
{
Mat grayImage;
cvtColor(frame, grayImage, CV_BGR2GRAY);
equalizeHist(grayImage, grayImage);


std::vector<cv::Rect> faces;
face_cascade.detectMultiScale(grayImage, faces, 1.1, 2,  0|CV_HAAR_SCALE_IMAGE, cv::Size(60, 60));

for (int i = 0; i < faces.size(); i++)
{
    // visualize the faces
    cv::Point pt1(faces[i].x + faces[i].width, faces[i].y + faces[i].height);
    cv::Point pt2(faces[i].x, faces[i].y);
    cv::rectangle(frame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8 ,0);
    // detect the eyes within the facial roi
    cv::Rect rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    cv::Mat roi = grayImage(rect);
    std::vector<cv::Rect> eyes;

    eyes_cascade.detectMultiScale(roi, eyes, 1.1, 2,  0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
    //eyesCascade.detectMultiScale(roi, eyes);
     for (int j = 0; j < eyes.size(); j++) 
   {

    cv::Point pt1(faces[i].x + eyes[j].x + eyes[j].width, faces[i].y + eyes[j].y + eyes[j].height);
    cv::Point pt2(faces[i].x + eyes[j].x, faces[i].y + eyes[j].y);
    cv::rectangle(frame, pt1, pt2, cvScalar(0, 210, 255, 0), 1, 8 ,0);
    }

}
imshow( window_name, frame );

 }