C++ 摄像头与Opencv接口:
我在DELL Inspiron 5537上安装了Windows 8,我从virtual box创建了一个虚拟机,并在其中安装了Ubuntu 13.04。然后我通过Ubuntu终端上的命令安装了Opencv版本=2.4.9。现在我想在Opencv中进行摄像头接口,这对我的项目向前发展是非常必要的。我的代码没有错误,仍然没有按照我想要的方式工作。 我的代码如下:C++ 摄像头与Opencv接口:,c++,opencv,ubuntu,virtual-machine,virtualbox,C++,Opencv,Ubuntu,Virtual Machine,Virtualbox,我在DELL Inspiron 5537上安装了Windows 8,我从virtual box创建了一个虚拟机,并在其中安装了Ubuntu 13.04。然后我通过Ubuntu终端上的命令安装了Opencv版本=2.4.9。现在我想在Opencv中进行摄像头接口,这对我的项目向前发展是非常必要的。我的代码没有错误,仍然没有按照我想要的方式工作。 我的代码如下: #include <iostream> #include <cv.h> #include <highgui.
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;
char key;
int main()
{
cvNamedWindow("Camera_Output", 1); //Create window
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
//Capture using any camera connected to your system
while(1){ //Create infinte loop for live streaming
IplImage* frame = cvQueryFrame(capture); //Create image
frames from capture
cvShowImage("Camera_Output", frame); //Show image
frames on created window
key = cvWaitKey(10); //Capture Keyboard stroke
if (char(key) == 27){
//cvSaveImage("webcam_frame.png",frame);
}
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
return 0;
}
当我在我的终端上运行此代码时,它并没有捕获图像,而是显示一个空白窗口。我已附上此代码输出的照片。您是否有opencv的控制台日志/错误?另外,试着运行cheese并检查摄像头是否正常工作。请告诉我什么是cheese,我们在opencvcheese中没有日志/错误。cheese是一个应用程序,您可以安装在Ubuntu上,或者默认安装,它使用摄像头拍照等。您可以检查摄像头是否在系统中工作。很可能您的虚拟机未正确配置为使用内置网络摄像头。