convert video to image and save it
hi
I want to convert video to image and save it
Opencv Can you do it?
Thanks in advance...
Hi Javani,
Yes you can do it (assuming that you have the proper codecs installed to read the video). I think it is a beautiful exercise to get acquainted with OpenCV, you can do something like this:
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
int main (int argc, char **argv)
{
if (argc !=2)
{
std::cout << "USE: " << argv[0] << " <video-filename>" << std::endl;
return 1;
}
//Open the video that you pass from the command line
cv::VideoCapture cap(argv[1]);
if (!cap.isOpened())
{
std::cerr << "ERROR: Could not open video " << argv[1] << std::endl;
return 1;
}
int frame_count = 0;
bool should_stop = false;
while(!should_stop)
{
cv::Mat frame;
cap >> frame; //get a new frame from the video
if (frame.empty())
{
should_stop = true; //we arrived to the end of the video
continue;
}
char filename[128];
sprintf(filename, "frame_%06d.jpg", frame_count);
cv::imwrite(filename, frame);
frame_count++;
}
return 0;
}
Note that I just coded this "on the fly", I don't know if the code compiles or works properly, but you get the idea.
Also, ffmpeg can convert a video to images and you don't need to code anything.
I hope this helps
You can have some thing like
cvSaveImage("image.jpeg",frame);
hi i am using ur code for my learning can u please tel me how can i store this images to specific folder? iam using strcpy("path name",filename); but it shows " Access violation writing location 0x00007FF7D4633318." at run time?
Asked: 2012-11-24 02:03:34 -0600
Seen: 10,150 times
Last updated: Nov 24 '12