简体   繁体   English

使用VideoCapture(OpenCV)从图像创建视频

[英]Create Video from images using VideoCapture (OpenCV)

I would like to write all my image files entitled "pictures_1/2/3/etc..." into a video file. 我想将所有名为“ pictures_1 / 2/3 / etc ...”的图像文件写入视频文件。

The code below is creating the video.avi file successfully. 下面的代码成功创建了video.avi文件。 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)) 我知道,videocapture OpenCV的功能主要用于从视频采集数据,但我听说这是可以使用它的图像太(如上所述这里 (1RST答案))

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. 确保图像已成功加载,只需在while循环中使用imshow()即可。

  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. 您的图像尺寸可以是1989X1680以外的任何尺寸,因此可以将图像调整为给定尺寸,或者设置视频分辨率以输入图像尺寸。

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

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