Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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);
}

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)'|
cv::MatExpr)
error: conversion from 'cv::Rect' to non-scalar type 'cv::Mat' requested|

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);
}