Created
October 11, 2012 14:10
-
-
Save matiasfha/3872566 to your computer and use it in GitHub Desktop.
Camera Capture OpenCV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cv.h" | |
#include "highgui.h" | |
#include <stdio.h> | |
// A Simple Camera Capture Framework | |
int main() { | |
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY ); | |
if ( !capture ) { | |
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 ( 1 ) { | |
// Get one frame | |
IplImage* frame = cvQueryFrame( capture ); | |
if ( !frame ) { | |
fprintf( stderr, "ERROR: frame is null...\n" ); | |
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 housekeeping | |
cvReleaseCapture( &capture ); | |
cvDestroyWindow( "mywindow" ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to convert the webcam output become grayscale or black? I try cvCvtColor but it's not work. Any way I can do that?