Debug assertion failed. Expression: vector subscript out of range

asked 2015-01-06 11:34:23 -0500

vinay gravatar image

updated 2015-01-06 12:12:21 -0500

I am trying to recognize face through ipcam using eigenface recognizer in Visual studio.. But I am getting the error

int main(int argc, const char *argv[]) {

string fn_haar = "C:\\haar\\haarcascade_frontalface_default.xml";
string fn_csv = "csv.ext";
const std::string videoStreamAddress =    // Ipaddress of the camera

vector<Mat> images;
vector<int> labels;

try {
    read_csv(fn_csv, images, labels);
} catch (cv::Exception& e) {
    cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
    exit(1);
}

int im_width = images[0].cols;
int im_height = images[0].rows;

Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
model->train(images, labels);

CascadeClassifier haar_cascade;
haar_cascade.load(fn_haar);

VideoCapture cap;

if(!cap.open(videoStreamAddress)) {
    cerr << "IPcam cannot be opened." << endl;
    return -1;
}

Mat frame;
for(;;) {
    cap >> frame;
    Mat original = frame.clone();
    Mat gray;
    cvtColor(original, gray, CV_BGR2GRAY);
    vector< Rect_<int> > faces;
    haar_cascade.detectMultiScale(gray, faces);

    for(int i = 0; i < faces.size(); i++) {

        Rect face_i = faces[i];
        Mat face = gray(face_i);

        Mat face_resized;
        cv::resize(face, face_resized, Size(im_width, im_height), 1.0, 1.0, INTER_CUBIC);
edit retag flag offensive close merge delete

Comments

ballistic search : images[0].cols

please check: images.empty() before. it might not have found your 'fn_csv' file at all. (try an 'absolute' path for that)

berak gravatar imageberak ( 2015-01-06 13:20:41 -0500 )edit

Thanks for your reply berak, I checked it and you are right that images is empty.. I tried giving absolute path to fn_csv. But still showing that "images is empty" and "debug assertion failed. Expression: vector subscript out of range"

vinay gravatar imagevinay ( 2015-01-06 23:08:53 -0500 )edit