Ask Your Question
1

How to extract Frames from AVI video

asked 2013-01-18 10:51:25 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Hey peeps so far i manage OpenCV to play a video.avi but what should i do now extract frames...?

below is the code i written so far that got my video playing:

#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv\ml.h>
#include<opencv\cxcore.h>



int main( int argc, char** argv ) {
cvNamedWindow( "DisplayVideo", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( argv[1] );
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "DisplayVideo", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow("DisplayVideo" );
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-01-18 11:43:04 -0500

AMP gravatar image

Try this.(press "f" button to save frame)
it's your code with some changes!

#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv\ml.h>
#include<opencv\cxcore.h>
#include<fstream>



int main( int argc, char** argv ) {
cvNamedWindow( "DisplayVideo", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( argv[1] );
IplImage* frame;
int num=0;
char s [20];
while(1) {
num++;
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "DisplayVideo", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
if (c == 'f')
{
sprintf(s,"frame%d.jpg",num);
cvSaveImage(s,frame);

}
}
cvReleaseCapture( &capture );
cvDestroyWindow("DisplayVideo" );
}
edit flag offensive delete link more

Comments

WOW this is exactly what i was looking for many thx, dont wont to be pushy but could you explain what your changes do and how, also is it possible to referee to these captured frames and process them like blur, threshold bounding box.....? regards

Tomazi gravatar imageTomazi ( 2013-01-18 12:01:35 -0500 )edit

if (c == 'f')

{

sprintf(s,"frame%d.jpg",num);

cvSaveImage(s,frame);

}

this part save image when you press f

if you want to process them you can type what you want in "for loop" and then save output. cvSaveImage(s,output)

AMP gravatar imageAMP ( 2013-01-19 05:33:44 -0500 )edit

How to do that same thing using Python and OpenCV?

prakharmohan gravatar imageprakharmohan ( 2014-03-13 23:50:40 -0500 )edit

where the files are saved?

Mahavir gravatar imageMahavir ( 2014-07-02 04:41:58 -0500 )edit

sprintf(s,"YOUR_DIRECTORY/frame%d.jpg",num);

AMP gravatar imageAMP ( 2014-08-10 11:45:15 -0500 )edit

Where is data video resource?

serdarkaracay gravatar imageserdarkaracay ( 2015-08-09 15:14:16 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-01-18 10:51:25 -0500

Seen: 8,331 times

Last updated: Jan 18 '13