Load many images in vector<Mat>
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!
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.what's the error message you get?
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!!!