Ask Your Question

Revision history [back]

There are some problems with your code:

  1. If you want to read a lot of images, do not use their names as command line arguments. Instead, put their names into a file and use that file name as one argument. Thus, your command line is shorter and neater and this helps to avoid the limitation of the number of command line arguments for a program.
  2. If your put a local Mat into an outside vector<mat>, you have to remove the img.release() statement since it frees the memory for the object that is being managed by the vector. Or, in case you keep the img.release() statement, you have to put each clone of one read image.
  3. If your images are of the same size and you know their number, you should initiate a vector<mat> using those parameters such as: vector<mat> imagesArg(300, cv::Mat(128, 128, CV_8U)); and then you can read each image as: imagesArg[i] = imread(imgNames[i], 0);

In fact, 300 images are not huge with a program and the idea of keeping images in a vector is not a good approach. You'd better read each image, process it, then store the results of all the images in a vector.