I have a problem to open many video files (e.g., 200) in a loop by using the OpenCV class VideoCapture. Below you can find my code.
More specifically, my program succeeds to open a certain number of videos (usually 171-173) but then it fails to open the others. I even tried to open always the same file (like in the example below) but the behaviour is the same.
In my opinion it should not be a memory leak problem (actually there is memory leak, but consumes only about 50MB in total). I think it is related to the fact that, when each video is opened, several threads are also opened and never closed, so they accumulate. But I don't know if this is the real reason or, if it is, how to solve it.
I'm using Visual Studio to compile, and Windows 7 OS.
Please let me know if you have any clue and/or solution.
string video_filename = "MyVideo.mp4";
for(int j=0; j<200; j++)
{
VideoCapture video(video_filename);
if(!video.isOpened())
{
cout << "Video #" << j << " could not be opened" << endl;
}
video.release(); // I've tried also to comment this out
}
I think you can easily try to reproduce this problem, as the code is very simple.