There were a few problems with your code.
- It was a mess and poorly identified;
- , . :
cvCaptureFromAVI(); cvQueryFrame() , ;- RGB → GREY:
cvCvtColor(frame, gray, CV_RGB2GRAY); ; - ;
/ , ?
int main()
{
CvCapture* capture = cvCaptureFromAVI( "macroblock.mpg" );
if ( !capture )
{
fprintf( stderr, "Cannot open AVI!\n" );
return 1;
}
int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
printf("FPS: %d\n", fps);
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "grayvideo", CV_WINDOW_AUTOSIZE );
int key = 0;
IplImage* gray = NULL;
IplImage* prev_frame = NULL;
while( key != 'x' )
{
frame = cvQueryFrame( capture );
if (!frame)
{
break;
}
cvShowImage( "video", frame );
if (!gray)
{
gray = cvCreateImage(cvGetSize(frame), frame->depth,1);
}
cvCvtColor(frame, gray, CV_RGB2GRAY);
cvShowImage( "grayvideo", gray );
if (!prev_frame)
{
prev_frame = cvCreateImage(cvGetSize(frame), frame->depth,1);
cvCopy( frame, prev_frame, 0 );
}
cvCopy( frame, prev_frame, 0 );
key = cvWaitKey( 1000 / fps );
if ( key==27 )
break;
}
cvDestroyWindow( "video" );
cvDestroyWindow( "grayvideo" );
cvReleaseCapture( &capture );
if (gray)
cvReleaseImage( &gray );
if (prev_frame)
cvReleaseImage( &prev_frame );
return 0;
}