Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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?

click to hide/show revision 2
retagged

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?