I am doing a project for video monitoring.
I can't see the conversion from RGB to gray; I get a black window for the gray.
Could you please help me with the problem? (code attached)
Also, how can I get the difference between current frame and previous frame?
Thanks a lot.
Ilan
#include "stdafx.h"
#include <stdio.h> // For printf
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main()
{
int key = 0;
CvCapture* capture = cvCaptureFromAVI( "macroblock.mpg" );
IplImage* frame = cvQueryFrame( capture );
IplImage* gray = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,1);
cvCvtColor(frame, gray, CV_RGB2GRAY);
if ( !capture )
{
fprintf( stderr, "Cannot open AVI!\n" );
return 1;
}
int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "grayvideo", CV_WINDOW_AUTOSIZE );
while( key != 'x' )
{
frame = cvQueryFrame( capture );
if(key==27 )break;
cvShowImage( "video",frame );
cvShowImage( "grayvideo",gray );
key = cvWaitKey( 1000 / fps );
}
cvDestroyWindow( "video" );
cvReleaseCapture( &capture );
return 0;
}