相同的消息:矢量下标超出范围

时间:2016-02-27 19:33:43

标签: c++ visual-studio-2010 vector

void EyeDetection (Mat Orig_frame)
{
Mat L_crop,R_crop,Gray_frame,Res_frame; vector<Rect>eyes;
vector<Rect>eyes1;

cvtColor(Orig_frame, Gray_frame, CV_BGR2GRAY);              
//Converts RGB to GrayScale

equalizeHist(Gray_frame, Gray_frame);                   
//Using histogram Equalization tech for improving contrast

eye_cascade.detectMultiScale(Gray_frame, eyes, 1.15, 4, 0 | CASCADE_SCALE_IMAGE,Size(10, 10)); //Detect Eyes
eye_cascade.detectMultiScale(Gray_frame, eyes1, 1.15, 4, 0 | CASCADE_SCALE_IMAGE,Size(10, 10)); //Detect Eyes

Rect L_roi,R_roi; //region of interest  

int x1, y1;                             //(x1,y1) is indx of left detected eye
int w1, h1;                             //width and height of detected eye

int x2, y2;                             //(x2,y2) is indx of right detected eye
int w2, h2;                             

int e_x1, e_y1;                             //(e_x1,e_y1) is indx of left eye after pruning
int e_w1, e_h1;                             //width and height of eye after pruning

int e_x2, e_y2;                             //(e_x2,e_y2) is indx of right eye after pruning
int e_w2, e_h2;

if ( !eyes.empty() ) {

    if ( eyes[0].width > 0 && eyes[0].height > 0) {         //First Detected eyes
        x1 = eyes[0].x;                     //Dimesnions of Left Detected eye in frame
        y1 = eyes[0].y;
        w1 = eyes[0].width;
        h1 = eyes[0].height;

        L_roi.x = e_x1 = x1 + .11*w1;                           //pruning Left eye to eliminate unwanted pixels (resizing)
        L_roi.y = e_y1 = y1 + .15*h1;
        L_roi.width = e_w1 = .8*w1;
        L_roi.height = e_h1 = .65*h1;

        Point L_pt1(e_x1,e_y1);
        Point L_pt2(e_x1 + e_w1, e_y1 + e_h1);

        L_crop = Gray_frame(L_roi);
        Mat left;
        rectangle(Orig_frame, L_pt1, L_pt2, Scalar(0, 255, 0), 2, 8, 0);
        imshow("Left Eye",L_crop);

    }


    if ( eyes1[0].width > 0 && eyes1[0].height > 0) {           //Second Detected eyes
        x2 = eyes1[1].x;                        //Dimension of Right Detected eye in frame
        y2 = eyes1[1].y;
        w2 = eyes1[1].width;
        h2 = eyes1[1].height;

        R_roi.x = e_x2 = x2 + .11*w2;                           //pruning Right eye to eliminate unwanted pixels (resizing)
        R_roi.y = e_y2 = y2 + .15*h2;
        R_roi.width = e_w2 = .8*w2;
        R_roi.height = e_h2 = .65*h2;

        Point R_pt1(e_x2, e_y2);
        Point R_pt2(e_x2 + e_w2, e_y2 + e_h2);

        R_crop = Gray_frame(R_roi);
        rectangle(Orig_frame, R_pt1, R_pt2, Scalar(0, 255, 0), 2, 8, 0);
        imshow("Right Eye",R_crop);

    }
   }
  }

我试图用Opencv为我的论文项目兄弟进行眼动追踪,但每次我都面对矢量超出范围的问题。因此我尝试在代码内部解决它,我创建第二个矢量,如eye1但它不起作用。并且当我们想到,如果我用手闭上我的一只眼睛,这会导致阻挡框架还是与问题有任何联系?请大家,我相信你最后一次改变我会告诉我的老师:-)我希望我们能找到问题。谢谢。

http://i.stack.imgur.com/HCWZ9.jpg“错误讯息图片”

0 个答案:

没有答案