简体   繁体   English

如何使用 Chrono 和 OpenCV 计算实时视频流的 FPS?

[英]How to calculate FPS of a live video stream using Chrono and OpenCV?

For a while I've been trying to calculate the FPS of a video stream coming through my OpenCV program, and was wondering if there's any way to do it using Chrono rather than time.h or any other API that measures with CPU ticks.有一段时间我一直在尝试计算通过我的OpenCV程序传入的视频流的 FPS,并且想知道是否有任何方法可以使用Chrono而不是time.h或任何其他使用 CPU 滴答进行测量的 API 来做到这一点。 After a good amount of experimenting and researching, I haven't found a simple solution using Chrono .经过大量的试验和研究,我还没有找到使用Chrono的简单解决方案。

Is there a Keep-It-Simple-Stupid solution to calculating your FPS with Chrono ?是否有使用Chrono计算 FPS 的 Keep-It-Simple-Stupid 解决方案? Or is working with CPU ticks unavoidable?还是不可避免地使用 CPU 滴答声?

You got the method你掌握了方法

VideoCapture::get(CV_CAP_PROP_FPS) Is it not working? VideoCapture::get(CV_CAP_PROP_FPS)不行吗?

As far as I know a chrono approach would still use CPU Ticks.据我所知,计时方法仍然会使用 CPU Ticks。 Supposing your loop is something like假设您的循环类似于

cv::Mat frame; cv::VideoCapture cap(video_path);
while (cap.read(frame)) {
     /* .. */
}

You could try something like你可以尝试类似的东西

#include <chrono>
using namespace std::chrono;

time_point<steady_clock> begin_time = steady_clock::now(), new_time;
cv::Mat frame; 
cv::VideoCapture cap(video_path);
size_t frame_counter = 0;

while (cap.read(frame)) {
    /* do stuff.. */ 
    frame_counter++;
    new_time = steady_clock::now();

    if (new_time - begin_time >= seconds{1}) {
        /* Do something with the fps in frame_counter */
        frame_counter = 0;
        begin_time = new_time;
    } 
}

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

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