1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| // C++ includes.
#include <iostream>
// OpenCV includes.
#include <cv.h>
#include <highgui.h>
struct CvCapture {};
struct CvVideoWriter{};
int main(int argc, char* argv[])
{
CvCapture* capture = cvCaptureFromAVI("/home/guillaume/test.AVI");
if(!cvGrabFrame(capture))
{ // capture a frame
printf("Could not grab a frame\n\7");
exit(0);
}
IplImage* img = 0;
img=cvRetrieveFrame(capture);
cvReleaseCapture(&capture);
CvVideoWriter *writer = 0;
int isColor = 0;
int fps = 25; // or 30
int frameW = 720; // 744 for firewire cameras
int frameH = 576; // 480 for firewire cameras
writer=cvCreateVideoWriter("/home/guillaume/toi.avi",CV_FOURCC('D', 'I', 'V', 'X'),
fps,cvSize(frameW,frameH),isColor);
int i;
int nFrames = 50;
for(i=0;i<nFrames;i++)
{
cvGrabFrame(capture); // capture a frame
img=cvRetrieveFrame(capture); // retrieve the captured frame
cvWriteFrame(writer,img); // add the frame to the file
cvShowImage("Win", img);
int key;
key=cvWaitKey(20);
}
cvNamedWindow("Win", CV_WINDOW_AUTOSIZE);
cvReleaseVideoWriter(&writer);
cvWaitKey(0);
cvDestroyWindow("Win");
return 0;
} |
Partager