我在使用OpenCV 2.4.3时遇到了访问Webcam的问题。
我的系统配置:
Hp Probook 4530s - HP Fixed HD Webcam
Ubuntu 12.10
OpenCV 2.4.3
如果我想捕捉我的内置相机,会出现ERROR: capture is NULL的错误。
我正在使用http://opencv.willowgarage.com/wiki/CameraCapture的示例代码。
示例代码如下:
#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;
}
我也尝试在终端输入xawtv -hwscan。结果如下:
looking for available devices
port 129-144
type : Xvideo, image scaler
name : Intel(R) Textured Video`
/dev/video0: OK
[ -device /dev/video0 ]
type : libv4l
name : HP HD Webcam [Fixed]
flags: capture
那么我可以通过输入xawtv video0来访问我的网络摄像头。我认为我的网络摄像头没有问题。我遇到的问题是与OpenCV有关。
VideoCapture cap(0);
,例如1和2。如果这样做没有帮助,那么问题就不是OpenCV引起的。 - Niko