如何找到视频的帧率使用c++ opencv 2.4.10



实际上,我正在尝试使用c++ opencv 2.4.10从视频中检测和跟踪车辆。我照做了。现在,我想求出输出视频的帧率。我想知道有没有办法查出来。谁能给我推荐一些关于这个的博客或教程?

谢谢。

这样做可能会有帮助。

#include <iostream>
#include <opencv2/opencv.hpp> //for opencv3
#include <opencv/cv.hpp> //for opencv2
int main(int argc, const char * argv[]) {
    cv::VideoCapture video("video.mp4");
    double fps = video.get(cv::CAP_PROP_FPS);
    std::cout << "Frames per second : " << fps << std::endl;
    video.release();
    return 0;
}

你必须在你的代码中有一个循环,你正在做所有的视频处理。

假设你有类似于下面的伪代码:

//code initialization
cv::VideoCapture cap("some-video-uri");
//video capture/processing loop
while (1)
{
        //here we take the timestamp
        auto start = std::chrono::system_clock::now();
        //capture the frame
        cap >> frame;
        //do whatever frame processing you are doing...
        do_frame_processing();
        //measure timestamp again
        auto end = std::chrono::system_clock::now();
        //end - start is the time taken to process 1 frame, output it:
        std::chrono::duration<double> diff = end-start;
        std::cout << "Time to process last frame (seconds): " << diff.count() 
                  << " FPS: " << 1.0 / diff.count() << "n";
}

就是这样……考虑到以每帧为基础计算FPS可能会产生高度不同的结果。为了得到一个变化较小的FPS,你应该把这个结果平均几帧。

最新更新