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
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<opencv/cv.h>
#include<opencv/highgui.h>
int main( int argc, char* argv[])
{
CvCapture* capture = 0;
capture = cvCreateFileCapture( argv[1] );
if(!capture)
return(-1);
IplImage* bgr_frame = cvQueryFrame(capture); // initialisation du lecteur
double fps = cvGetCaptureProperty( capture, CV_CAP_PROP_FPS) ; // fps donne la vitesse de deroulement des frames
CvSize size = cvSize( (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT));
CvVideoWriter *writer = cvCreateVideoWriter( argv[2], CV_FOURCC('P','I','M','1'), fps, size,1);
IplImage* gray_frame = cvCreateImage( size,bgr_frame->depth,1);
IplImage* out_frame = cvCreateImage( size,bgr_frame->depth,3);
// chaque frame est transformee en image gris
while((bgr_frame = cvQueryFrame(capture)) != NULL)
{
cvCvtColor(bgr_frame, gray_frame, CV_RGB2GRAY);
cvCvtColor(gray_frame, out_frame, CV_GRAY2RGB);
cvWriteFrame( writer, out_frame );
}
// liberation de la memoire
cvReleaseVideoWriter(&writer);
cvReleaseImage( &gray_frame );
cvReleaseImage( &out_frame );
cvReleaseCapture( &capture );
return(0);
} |
Partager