-1

I am labeling my images but this part of my code give me error runtime error , where i assign the labels to it , when i remove this line code runs fine :

int count_2=0;
cv::Mat training_mat(num_img , dictionarySize,CV_32FC1);
cv::Mat labels(0,1,CV_32FC1);

for (k = all_names.begin(); k != all_names.end(); ++k)
{
    Dir=( (count_2 < files.size() ) ? YourImagesDirectory : YourImagesDirectory_2);

    Mat row_img_2 = cv::imread( Dir +*k, 0 );

    detector.detect( row_img_2, keypoints);

    RetainBestKeypoints(keypoints, 20);

    dextract.compute( row_img_2, keypoints, descriptors_1);

    Mat my_img = descriptors_1.reshape(1,1);

    my_img.convertTo( training_mat.row(count_2), CV_32FC1 );
    //training_mat.push_back(descriptors_1);

    ***Here is the error***
    //labels.at< float >(count_2, 0) = (count_2<nb_face)?1:-1; // 1 for face, -1 otherwise*/
    ++count_2;
}

Above the part of my code , i want to give 1 to the directory which contain positive images and -1 to the directory of images which contain negative images , nb_face is the file.size() of positive images

Rocket
  • 553
  • 8
  • 31

1 Answers1

0

You need to give a size to the label vector when you create it. Otherwhise you get an error that you access the label vector using out of bounds indicies.

So try to change

cv::Mat labels(0,1,CV_32FC1);

to

cv::Mat labels(num_img,1,CV_32FC1);
sietschie
  • 7,425
  • 3
  • 33
  • 54
  • Which approach is better to use here : my_img.convertTo( training_mat.row(count_2), CV_32FC1 ); or training_mat.push_back(descriptors_1); – Rocket Aug 29 '13 at 17:07