我在使用opencv 2.4.3访问摄像头时遇到了问题。Opencv无法访问我的摄像头
我几乎到处都是Google搜索,但我无法解决我的问题。
我的系统:
惠普ProBook 4530s - 惠普固定的高清摄像头
的Ubuntu 12.10
的OpenCV 2.4.3
如果我想捕捉我的内置摄像头,收到错误: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。
如果您使用C++给这个示例代码一个尝试:http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture – Niko
我尝试您的代码是在http:// docs。 opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture 它不工作 – burakim
尝试在这里使用不同的数字:'VideoCapture cap(0);',例如1和2.如果这没有帮助,问题不在OpenCV中。 – Niko