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
| #include "cv.h"
#include "highgui.h"
#include <stdio.h>
void capture_webcam()
{
CvCapture* capture;
unsigned char *p;
int x,y, num=0;
char filename[10];
capture = cvCaptureFromCAM(0);
if( !capture )
{
fprintf(stderr,"Could not initialize capturing...\n");
return;
}
printf("\tPress ESC to quit the program\n");
cvNamedWindow( "CaptureCam", 1);
for(;;)
{
IplImage* frame = 0;
// Capture un frame,
frame = cvQueryFrame( capture );
if( !frame ) break;
// l' affiche,
cvShowImage( "CaptureCam", frame );
// l'enregistre sur le disque
sprintf(filename, "frame%04d.jpg", num++);
cvSaveImage(filename, frame);
if( cvWaitKey(10) == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow("CaptureCam");
}
int main()
{
capture_webcam();
return 0;
} |
Partager