我有一个从我的Web摄像头(内置于惠普DV5)捕获图像的问题。唯一的结果是灰色屏幕。以下是代码:
#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;
}
这是修改自OpenCV维基的代码。我知道用这种方法找相机很疯狂,但使用-1或0并没有起作用。我添加了一些额外的属性(已注释),但仍然没有起作用。提前感谢您的帮助 :) 问候, Chris