/**
* TUTORIAL OPENCV
* EXEMPLO 5: Exibir um vídeo à partir de uma câmera ou arquivo
*
* @author   MALF - malf@tecgraf.puc-rio.br
* @date     29/06/07
*/

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "cvcam.h"
#include "cv.h"
#include "highgui.h"

/************************************************************************
 * 
 ************************************************************************/
int main( int argc, char** argv )
{
  IplImage* frame, *frame_copy = 0;
  CvCapture* capture = 0;
   
  capture = cvCaptureFromCAM(0); 
  cvNamedWindow( "result", 1 );

  
  for(;;)
  {
     if( !cvGrabFrame( capture ))
          break;
            
	 frame = cvRetrieveFrame( capture );
     if( !frame )
          break;
            
	 if( !frame_copy )
                frame_copy = cvCreateImage( cvSize(frame->width,frame->height),
                                            IPL_DEPTH_8U, frame->nChannels );
     if( frame->origin == IPL_ORIGIN_TL )
           cvCopy( frame, frame_copy, 0 );
     else
           cvFlip( frame, frame_copy, 0 );
            
     /* detect_and_draw( frame_copy ); */
	 cvShowImage("result", frame );


     if( cvWaitKey( 10 ) >= 0 )
         goto _cleanup_;
  }

  cvWaitKey(0);

_cleanup_:

  cvReleaseImage( &frame_copy );
  cvReleaseCapture( &capture );

  cvDestroyWindow("result");

  return 0;
}


