I have a problem with capturing image from my web cam (built in hp dv5). The only result is grey screen. Here's the code:
#include "StdAfx.h"
#include "cv.h"
#include "highgui.h"
#include <stdio.h> // A Simple Camera Capture Framework
int main() {
CvCapture* capture;
for (int i = -1;i < 100;i++) {
capture = cvCaptureFromCAM( i );
if( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
} else {
break;
}
}
//cvSetCaptureProperty( capture, CV_CAP_PROP_FPS,15);
//cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 160 );
//cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 120 );
// 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 );
cvGrabFrame(capture);
frame = cvRetrieveFrame(capture);
if( !frame ) {
fprintf( stderr, "ERROR: frame is null...\n" );
getchar();
break;
} else {
fprintf( stderr, "OK\n" );
}
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
int c = cvWaitKey(100);
} // Release the capture device housekeeping
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
It's modified code from OpenCV's wiki. I know that finding the camera in this way its crazy but it didn't work with -1 or 0. I added some additional properties (commented already) but it didn't work anyway. Thanks in advance :) Greetings, Chris