Create video from images with VideoCapture (OpenCV)

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

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

I know that the video capture function is mainly used for capturing data from video, but I heard that it is possible to use it for images too ( as described here (1st 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);
  }
}

      

+1


source to share


1 answer


Possible reason for the missing video.



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

  • Your image size can be any size other than 1989X1680, so either resize the image to the given size or specify the video resolution to enter the image size.

+3


source







All Articles