OpenCV - 从播放显着增加帧速率 [英] OpenCV - Dramatically increase frame rate from playback

查看:981
本文介绍了OpenCV - 从播放显着增加帧速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OpenCV中有一种方法可以大幅提高视频的帧速率(.mp4)。我尝试了增加视频播放的方法,包括:

In OpenCV is there a way to dramatically increase the frame rate of a video (.mp4). I have tried to methods to increase the playback of a video including :

提高帧速率:

code> cv.SetCaptureProperty(cap,cv.CV_CAP_PROP_FPS,int XFRAMES)

cv.SetCaptureProperty(cap, cv.CV_CAP_PROP_FPS, int XFRAMES)

跳过框架:

for(int i = 0; i

&

video.set(CV_CAP_PROP_POS_FRAMES,(double)nextFrameNumber);

是否有另一种方法来达到所需的结果?任何建议都将非常感激。

is there another way to achieve the desired results? Any suggestions would be greatly appreciated.

更新
只是为了澄清,播放速度不慢,我只是搜索为一种方式,使其更快。

Update Just to clarify, the play back speed is NOT slow, I am just searching for a way to make it much faster.

推荐答案

您正在使用旧的API(cv.CaptureFromFile)从视频文件捕获。

You're using the old API (cv.CaptureFromFile) to capture from a video file.

如果您使用新的C ++ API,您可以按照您想要的速率抓取框架。下面是一个非常简单的示例代码:

If you use the new C++ API, you can grab frames at the rate you want. Here is a very simple sample code :

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap("filename"); // put your filename here

    namedWindow("Playback",1);

    int delay = 15; // 15 ms between frame acquisitions = 2x fast-forward

    while(true)
    {
        Mat frame;
        cap >> frame; 
        imshow("Playback", frame);
        if(waitKey(delay) >= 0) break;
    }

    return 0;
}

基本上,你只需在每个循环中抓取一个帧, code> cvWaitKey()。您在每个帧之间等待的毫秒数将设置您的加速。这里,我把15毫秒,所以这个例子将播放30 fps的视频在约。

Basically, you just grab a frame at each loop and wait between frames using cvWaitKey(). The number of milliseconds that you wait between each frame will set your speedup. Here, I put 15 ms, so this example will play a 30 fps video at approx. twice the speed (minus the time necessary to grab a frame).

另一个选择,如果你真的想要控制如何和你从视频文件抓取,是使用GStreamer API抓取图像,然后转换为OpenCV进行图像跟踪。您可以在此信息中找到有关此信息的一些信息: MJPEG流式传输和解码

Another option, if you really want control about how and what you grab from video files, is to use the GStreamer API to grab the images, and then convert to OpenCV for image tratment. You can find some info about this on this post : MJPEG streaming and decoding

这篇关于OpenCV - 从播放显着增加帧速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆