断言恐怖"矢量下标超出范围" 1140行

时间:2016-04-15 09:55:50

标签: c++ opencv vector haar-classifier

我是opencv的初学者。事情是我试图做的就是从主框架中裁剪眼睛区域。但是我得到了这样的错误" Assertion eror"矢量下标超出范围" 1140行。"你们有没有想过如何解决这个问题?

这是我的代码:

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> 
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;
int main(int argc, const char** argv)
{
CascadeClassifier eye;
CascadeClassifier righteye;
CascadeClassifier lefteye;


eye.load("haarcascade_mcs_eyepair_big.xml");
righteye.load("haarcascade_mcs_lefteye.xml");
lefteye.load("haarcascade_mcs_righteye.xml");

VideoCapture vid;
vid.open(0);

if (!vid.isOpened())
{
cout<<"webcam cannot open"<<endl;
system("Pause");
return -1;
}
Mat frame;
Mat grires;
Mat frame2;
Mat frame3;


namedWindow("algilanan",1 );
namedWindow("algilanan2",2);

namedWindow("algilanan3",3);


while(true)
{
vid>>frame;
cvtColor(frame, grires, CV_BGR2GRAY);  //resmi gri renk uzayına çevirir. 
//equalizeHist(grires, grires); //istenirse histogram eşitlenir. 
vector<Rect> eyepair;

eye.detectMultiScale(grires, eyepair, 1.1, 3, 0, Size(30,30));


for(int i = 0; i < eyepair.size(); i++)
{
Point pt1(eyepair[i].x + eyepair[i].width,eyepair[i].y + eyepair[i].height);
Point pt2(eyepair[i].x, eyepair[i].y);
rectangle(frame, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);

Mat ROI =grires(eyepair[i]);
vector<Rect> reye;
vector<Rect> leye;


righteye.detectMultiScale(ROI, reye, 1.1, 3, 0, Size(30,30));
lefteye.detectMultiScale(ROI, leye, 1.1, 3, 0, Size(30,30));

for(int t = 0; t < reye.size(); t++)
{


Point pt1(eyepair[i].x + reye[t].x, eyepair[i].x + reye[t].y + reye[t].height);
Point pt2(reye[t].x,reye[t].y);
rectangle(ROI, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);

Rect r1 = reye[t];
frame3=ROI(r1);
}

for(int z = 0; z < leye.size(); z++)
{
Point pt1(eyepair[i].x + leye[z].x, eyepair[i].x + leye[z].y + leye[z].height);
Point pt2(leye[z].x,leye[z].y);
rectangle(ROI, pt1, pt2, cvScalar(0, 255, 0, 0), 1, 8, 0);

Rect r2 = reye[z];
frame2=ROI(r2);
}



}


imshow("algilanan", frame);
imshow("algilanan2",frame2 );

imshow("algilanan3", frame3);



waitKey(33);
}
return 0;
}

0 个答案:

没有答案