Archive Video Episode
?Download WebCam.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cv.h"
#include "highgui.h"
int main(void)
{
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
//CvCapture* capture = cvCaptureFromAVI("infile.avi");
if( !capture ) {
std::cout<< "ERROR: capture is NULL" << std::endl;
getchar();
return -1;
}
//Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
IplImage* frame = cvQueryFrame( capture );
//Show the image captured from the camera in the window and repeat
while( 1 ) {
//Get one frame
IplImage* frame = cvQueryFrame( capture );
if( !frame ) {
std::cout<< "ERROR: frame is null..." << std::endl;
getchar();
break;
}
cvShowImage( "mywindow", frame );
//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
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
} |