#include "cv.h"
#include "highgui.h"
#include <iostream>
#include <cstdio>
using namespace std;
// A Simple Camera Capture Framework
int main()
{
CvCapture* pCapture = cvCaptureFromCAM( CV_CAP_ANY );
if( !pCapture )
{
cerr << "ERROR: capture is NULL!!" << endl << flush;
getchar();
return -1;
}
// Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while( 1 )
{
// Get one frame
IplImage* pFrame = cvQueryFrame( pCapture );
if( !pFrame )
{
cerr << "ERROR: frame is null..." << endl << flush;
getchar();
break;
}
cvShowImage( "mywindow", pFrame );
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator
if( (cvWaitKey(10) & 255) == 27 ) break;
}
// Release the capture device housekeeping
cvReleaseCapture( &pCapture );
cvDestroyWindow( "mywindow" );
return 0;
}
|