简体   繁体   English

OpenCV-显着提高播放的帧速率

[英]OpenCV - Dramatically increase frame rate from playback

In OpenCV is there a way to dramatically increase the frame rate of a video (.mp4). 在OpenCV中,有一种方法可以显着提高视频(.mp4)的帧速率。 I have tried to methods to increase the playback of a video including : 我尝试了一些方法来增加视频的播放,包括:

Increasing the frame rate: 增加帧频:

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

Skipping frames: 跳帧:

for( int i = 0; i < playbackSpeed; i++ ){originalImage = frame.grab();}

&

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. 更新只是为了澄清,播放速度并不慢,我只是在寻找一种使播放速度更快的方法。

You're using the old API (cv.CaptureFromFile) to capture from a video file. 您正在使用旧的API(cv.CaptureFromFile)从视频文件捕获。

If you use the new C++ API, you can grab frames at the rate you want. 如果使用新的C ++ API,则可以按所需的速率抓取帧。 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;
}

Basically, you just grab a frame at each loop and wait between frames using cvWaitKey() . 基本上,您只需在每个循环中抓取一帧,然后使用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. 在这里,我放了15毫秒,因此此示例将以大约30 fps的速度播放30 fps视频。 twice the speed (minus the time necessary to grab a frame). 两倍的速度(减去抓取框架所需的时间)。

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. 如果您真的想控制从视频文件中获取图像的方式和内容,另一种选择是使用GStreamer API捕获图像,然后转换为OpenCV进行图像处理。 You can find some info about this on this post : MJPEG streaming and decoding 您可以在这篇文章中找到有关此信息: MJPEG流和解码

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

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