I’m renewing an old code in C with C API OpenCV and I need to load at least 300 images in memory to make some algorithms with them.
So, I’ve been thinking that I can load that images in memory to make operations more faster instead to load from disk and make a single operation each one.
What is the best way to do that?
If you’re working with C code, then your images will automatically stay in memory until you explicitly release them. Simply call
cvLoadImageon each image you wish to load from disk. I would recommend you store theIplImage*pointers in a big array so you don’t lose track of them. When you’re done, simply callcvReleaseImageand the memory will all be freed.As you mentioned, you’ll have to watch out as you’re loading that you don’t run out of memory. If you do, you’ll have no option but to only load a subset into memory and keep the rest on disk.