【问题标题】:create a video from image sequence in open cv从打开的 cv 中的图像序列创建视频
【发布时间】:2014-03-28 04:31:04
【问题描述】:

我正在使用 c++ 开发开放式 cv。我有大约 30 帧图像。我需要将这些帧组合起来以获得视频。有人可以建议我方法吗?就像读取每一帧并存储在 videowriter 中一样吗?请建议

【问题讨论】:

    标签: c++ opencv video


    【解决方案1】:

    我建议使用 ffmpeg。您可以通过编程方式或使用命令行来执行此操作。在命令行上执行此操作的示例是:

    ffmpeg -start_number n -i image%d.jpg -vcodec mpeg4 test.avi
    

    其中 n 是第一个图像编号。

    【讨论】:

    • 我想以编程方式在 open cv 上而不是在命令行上进行
    • 我从来没有使用过 OpenCV,只有图像处理。不知道有没有可能。
    【解决方案2】:

    Tutorial how to do Videooutput

    系统将询问您要使用的编解码器。有点复杂,但是SO上已经有很多编解码相关的问题了。

    此代码应该可以工作(未经测试):

    #include <iostream> // for standard I/O
    #include <string>   // for strings
    #include <vector>
    #include <opencv2/core/core.hpp>        // Basic OpenCV structures (cv::Mat)
    #include <opencv2/highgui/highgui.hpp>  // Video write
    
    using namespace std;
    using namespace cv;
    
    int main(int argc, char *argv[], char *window_name){
        vector<Mat> images; //fill this somehow
        Size S = vector[0].getSize();    
    
        VideoWriter outputVideo;  // Open the output
        outputVideo.open(NAME  , ex=-1, 30), S, true);  //30 for 30 fps
    
        if (!outputVideo.isOpened()){
            cout  << "Could not open the output video for write: "<< endl;
            return -1;
        }
    
        for(int i=0; i<images.size(); i++){
            outputVideo << res;
        }
    
        cout << "Finished writing" << endl;
        return 0;
    }
    

    【讨论】:

    • 将图像填充到矢量中由您决定。你可以用命令行参数来做,或者硬编码,或者用其他方式来做......
    猜你喜欢
    • 2017-05-02
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    相关资源
    最近更新 更多