简体   繁体   中英

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?

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. You should average this result for several frames in order to get a less variant FPS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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