Wednesday, May 4, 2011

Episode_5_Working_with_Video

After working with camera Now we will play with video. Video ??? Of course, we can play video and capture the image with OpenCV. The Video should be in AVI files and you must put your video file into your project. Ok let's try it

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"

int main(int argc, char* argv[])
{
 IplImage *frame;
 int key = 'a';

 /* load the AVI file */
 CvCapture *capture = cvCaptureFromAVI("Video.avi");
 /* always check */
 if( !capture ) return 1;

 /* get fps, needed to set the delay */
 int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
 /* display video */
 cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
 while( key != 'q' )
 {
     /* get a frame */
     frame = cvQueryFrame( capture );

     /* always check */
     if( !frame ) break;
     /* display frame */
     cvShowImage( "video", frame );
     /* quit if user press 'q' */
     cvWaitKey( 1000 / fps );
 }

 /* free memory */
 cvReleaseCapture( &capture );
 cvDestroyWindow( "video" );
 return 0;
}


picture 0_working_with_video

You cann't hear the sound !! As OpenCV just stands for computer vision. it seems OpenCV didn't provide libraries that could process audio. OpenCV capture images not sound but I don't know if you can get some tricks.

0 comments:

Post a Comment