【发布时间】:2014-03-28 04:31:04
【问题描述】:
我正在使用 c++ 开发开放式 cv。我有大约 30 帧图像。我需要将这些帧组合起来以获得视频。有人可以建议我方法吗?就像读取每一帧并存储在 videowriter 中一样吗?请建议
【问题讨论】:
我正在使用 c++ 开发开放式 cv。我有大约 30 帧图像。我需要将这些帧组合起来以获得视频。有人可以建议我方法吗?就像读取每一帧并存储在 videowriter 中一样吗?请建议
【问题讨论】:
我建议使用 ffmpeg。您可以通过编程方式或使用命令行来执行此操作。在命令行上执行此操作的示例是:
ffmpeg -start_number n -i image%d.jpg -vcodec mpeg4 test.avi
其中 n 是第一个图像编号。
【讨论】:
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;
}
【讨论】: