使用VideoCapture(OpenCV)从图片创建视频 [英] Create Video from images using VideoCapture (OpenCV)

查看:318
本文介绍了使用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);
}
}



  1. 确保您的图片已成功加载,只需在while循环中使用imshow / p>


  2. 您的图片大小可以是除1989X1680之外的任何大小,因此您可以将图片调整为指定大小或设置视频分辨率以输入图片大小。



I would like to write all my image files entitled "pictures_1/2/3/etc..." into a video file.

The code below is creating the video.avi file successfully. However, there is no data written inside the latter.

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.

  1. Make sure that your image is successfully loaded, just use imshow() in while loop.

  2. 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)从图片创建视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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