Why does it takes so long to capture the frames and store them in memory?
So, I'm writting a program that loads a video in memory to determine if it's unstabilized. I realized the program was taking way too long to execute, so I put a timer on my code:
const clock_t begin = std::clock();
int frame_count = 0;
bool should_stop = false;
std::vector <cv::Mat> frames;
while(!should_stop)
{
cv::Mat frame;
cap >> frame;
frames.push_back(frame.clone());
if (frame.empty())
{
should_stop = true;
continue;
}
frame_count++;
}
std::cout << "Time: " << float( std::clock () - begin ) / CLOCKS_PER_SEC << std::endl;
But this prints times around ~0.70s as opposed as what I observe and measure with the time
command:
$ time ./program ~/Desktop/video.mp4
Time: 0.700728s
./program ~/Desktop/video.mp4 0,56s user 0,19s system 2% cpu 36,409 total
Any ideas on why this is happening?
If you combine user and system time, then you got the exact same value. BTW depending on the amount of frames, 0.7 seconds is quite fast I think ...
The thing is that the total time the program takes to run and return to the shell is 36,409s, leading me to think, the in-code timer measure is not right. And we're talking about ~200 frames, I agree 0.7s will be fast enough, but instead it runs in about 40s!