praxmon
praxmon

Reputation: 5121

Opening images one after the other

I have a series of images saved on my system according to their time stamps.

For example the images are named as:

20140305180348.jpg

20140305180349.jpg

I have 100 such images, I want to open them using OpenCV one after the other. I have tried using cvCapturefromFile() but using it I am able to open just a single image at a time. I want to stitch/join them so that I can make a video.

I am sorry I cannot post the code as I am not allowed to. How do I proceed?

Upvotes: 0

Views: 68

Answers (2)

herohuyongtao
herohuyongtao

Reputation: 50667

In OpenCV, to write images to a video, you can use VideoWriter (and do it in a loop to read a sequence of images):

VideoWriter outputVideo; // Open the output

// ... set video properties like FPS

if (!outputVideo.isOpened())
{
    cout  << "Could not open the output video for write: " << source << endl;
    return -1;
}

for(...)
{
   // read your frame, e.g. to Mat img

   // outputVideo.write(img); //save or
   outputVideo << img;
}

cout << "Finished writing" << endl;

Check out here for more info.

Upvotes: 2

Sebastian Schmitz
Sebastian Schmitz

Reputation: 1894

In this tutorial is an example how to write a video. Just modify the for-loop in the end.

pseudocode:

open videocontainer
int i=0;
while(i<100){
    Mat img = imread("path"+to_string(i)+".jpg");
    outputvideo << img;
}
close videocontainer

Upvotes: 1

Related Questions