how to convert sequence of images in to video? [closed]
Hello all, i want to convert sequence of images into video. i written the code it is not giving any error but the created .avi file is only 5.51 kb and nothing is playing with it. my code is
#include "opencv2/opencv.hpp"
#include <sstream>
#include <iostream>
#include "stdafx.h"
using namespace cv;
using namespace std;
Mat frame, img;
int i = 0;
int main(int, char**)
{
Size frame_size(256, 256);
//Size frame_size(frame_width, frame_height);
int frames_per_second = 30;
//Create and initialize the VideoWriter object
VideoWriter oVideoWriter("BIKINGSub.avi", VideoWriter::fourcc('M', 'J', 'P', 'G'),
frames_per_second, frame_size, true);
int z = 1;
char filename[80];
while (1)
{
sprintf_s(filename, "SubtractionResultsStatic/BIKING/biking_%d.png", z);
Mat frame = imread(filename, 1);
//If the VideoWriter object is not initialized successfully, exit the program
//resize(frame, frame, Size(320, 180));
oVideoWriter.write(frame); //writer the frame into the file
imshow("MyVideo", frame); //show the frame in "MyVideo" window
if (waitKey(10) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
z++;
}
printf("\ndone\n");
return 0;
}
please suggest what i'm doing wrong?
Mat frame = imread(filename, 1); what does it mean 1 ? use IMREAD_COLOR it will give you an image with three planes (not four as in png file)
check if rame is empty or not
a good idea is to close avi file too
are the images you read 256x256 ? (that's what you gave to the VideoWriter)
Use an ostringstream instead of the C sprintf.
For example:
Thanks a lot sir...problem resolved.