本文介绍了使用VideoCapture(OpenCV)从图片创建视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将所有我的图片文件pictures_1 / 2/3 / etc ...写入视频文件。
video.avi文件成功。
我知道videocapture opencv函数主要用于从视频捕获数据,但我听说它是也可以将其用于图片(如所述)
void video(void)
{
VideoCapture in_capture (/path/.../pictures_%d.jpg);
Mat img;
VideoWriter out_capture(path /.../ video.avi,CV_FOURCC('M','J','P','G'),30,Size 1989,1680));
while(true)
{
in_capture>> img;
if(img.empty())
break;
out_capture.write(img);
}
}
I would like to write all my image files entitled "pictures_1/2/3/etc..." into a video file.
I'm aware that the videocapture opencv function is mainly used to capture data from a video, but i heard it was possible to use it for images too (As described here (1rst answer))
void video (void)
{
VideoCapture in_capture("/path/.../pictures_%d.jpg");
Mat img;
VideoWriter out_capture("path/.../video.avi", CV_FOURCC('M','J','P','G'), 30, Size(1989,1680));
while (true)
{
in_capture >> img;
if(img.empty())
break;
out_capture.write(img);
}
}
解决方案
Possible reason for no video created.
Make sure that your image is successfully loaded, just use imshow() in while loop.
Your image size can be any size other than 1989X1680, so either resize your image to given size or set out video resoluton to input image size.
这篇关于使用VideoCapture(OpenCV)从图片创建视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!