简体   繁体   English

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

[英]How to find framerate of video using c++ opencv 2.4.10?

Actually,I am trying detect and track the vehicles from a video using C++ opencv 2.4.10.I did so.Now,I want to find the frame rate of the output video.I want to know if there is any way to find out.Can anyone suggest me any blog or tutorial about this?实际上,我正在尝试使用 C++ opencv 2.4.10 从视频中检测和跟踪车辆。我这样做了。现在,我想找到输出视频的帧率。我想知道是否有任何方法可以找出.任何人都可以向我推荐有关此的任何博客或教程吗?

Thank you.谢谢。

Something like this may help.像这样的事情可能会有所帮助。

#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;
}

You must have a loop in your code where you are doing all the video processing.您的代码中必须有一个循环,您可以在其中进行所有视频处理。

Let's say you have something similar to this pseudocode:假设您有类似于此伪代码的内容:

//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";
}

thats it ... take into account that calculating FPS in a frame-per-frame basis will likely produce a highly variant result.就是这样......考虑到以逐帧为基础计算 FPS 可能会产生高度变化的结果。 You should average this result for several frames in order to get a less variant FPS.您应该对几帧的结果进行平均,以获得更少变化的 FPS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM