#include "stdafx.h"
#include "cv.h" // includes OpenCV definitions
#include "highgui.h" // includes highGUI definitions
#include "cvcam.h"
#include <iostream>
#include <stdio.h>// includes C standard input/output definitions
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// Determine the number of available cameras
int numCameras = cvcamGetCamerasCount() ;
cout << "=========================================" << endl ;
cout << "== Located devices: =>" << numCameras << "<=" << endl ;
cout << "=========================================" << endl ;
// Make sure that a camera is attached
if( numCameras == 0 ) {
getchar();
return -1;
}
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if( capture ) {
printf( "=> OK/n");
} else {
fprintf(stderr,"ERROR: capture is NULL /n");
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( true ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if( !frame ) {
fprintf(stderr,"ERROR:frame is null.../n");
getchar();
break;
}
cvShowImage( "mywindow", frame );
int c = cvWaitKey(10);
if( c == 27 )
break;
}
cvcamStop();
cvcamExit();
// Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}