繁体   English   中英

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

[英]Same message:Vector subscript out of range

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进行眼动跟踪,但是每次遇到向量超出范围的问题时,我试图在代码中解决它,我创建了第二个向量,例如eyes1,但是它不起作用。 ,如果我用一只手闭上眼睛,这是否会导致框架阻塞或与该问题有任何关系?请大家,我相信您是最后一次更改,我会告诉我的老师:-)我希望我们可以发现问题。谢谢。

http://i.stack.imgur.com/HCWZ9.jpg “错误消息的图像”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM