所以,我正在编写一个程序,在内存中加载视频,以确定它是否不稳定。我意识到程序执行的时间太长,所以我在我的代码上放了一个计时器:
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;
然后,计时器打印约0.70秒左右的测量值(相当于约200帧),而不是我用time
命令观察和测量:
$ time ./program ~/Desktop/video.mp4
Time: 0.700728s
./program ~/Desktop/video.mp4 0,56s user 0,19s system 2% cpu 36,409 total
有关为何发生这种情况的任何想法?