Load many images in vector<Mat>

asked 2014-08-16 07:08:17 -0600

Azucena gravatar image

updated 2014-08-16 08:17:40 -0600

unxnut gravatar image

I'm trying to store multiple images in a folder on a vector <mat> for calculate SIFT and SURF features about it. I want to save image files in a vector<mat>, like this:

vector<mat> images; //Count is defined before

for (int a=0; a<Count ;a++)
{
    string name=format("C:\\Users\\Azu\\Documents\\Visual Studio 2010\\Projects\\SIFT2\\SIFT2\\BBDDFaces\\%d.pgm", a);
    images.push_back(imread(name));
}

But later, I can’t access to the vector images:

Imshow (“1”,images[0]);     //it works
Imshow(“2”,images[1]);      //it fails!!

I'd appreciate, if anyone can help me fix it!

edit retag flag offensive close merge delete

Comments

You should check if the images are read properly. Modify the code to cv::Mat img = imread(name);. Check if the image was read properly before pushing it back onto vector.

unxnut gravatar imageunxnut ( 2014-08-16 08:52:43 -0600 )edit

what's the error message you get?

hadoofi gravatar imagehadoofi ( 2014-08-16 15:30:26 -0600 )edit
1

So sorry for no response yesterday. I solved it by this way:

vector<Mat> images; int Count=); for (int a=0; a<Count;a++)
{ string name = format("C:\Folder\%d.pgm", a+1); Mat img = imread(name);
if ( img.empty() )
{ cerr << "\nERROR: Can't be loaded image" << name << endl; continue; } images.push_back(img); imshow("Vector of imgs",img); cvWaitKey(0); }

Thanks!!!

Azucena gravatar imageAzucena ( 2014-08-17 07:27:52 -0600 )edit