Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why is imread slowing down in a for loop?


I have about 3500 tiff files (unsigned 16bit, 2048 x 2048) stored in a directory. I wrote a c++ program to read the files using the imread function in a for loop. When I compile and run the program I am finding that the for loop runs nice and fast up to a certain point and then suddenly slows down to a bit of a crawl.

To be more specific, I declare a cv::Mat object before the loop and the Mat is just reallocated during each iteration. In other words I can't see how it could be a memory issue (I don't see my RAM usage increasing during run time).

Here is what the offending code looks like:

std::vector<cv::String> filenames;
cv::glob(path, filenames);
cv::Mat im;

for (size_t i = 1; i<(filenames.size()); i++)
    im = imread(filenames[i], CV_LOAD_IMAGE_ANYDEPTH);      
    std::cout << i << std::endl;

I am using openCV 3.4 and Visual Studio 2017 in release mode.

Can anybody help?