2015-11-04 107 views
3

我试图使用我的计算机上的摄像头实时捕获图像。 我使用虚拟盒子运行Ubuntu,并且我知道我需要设置USB设置才能使用网络摄像头,但是我仍然需要安装网络摄像头驱动程序吗?如果是的,我该怎么做!opencv视频捕获和虚拟机上的摄像头访问

我安装 的VirtualBox 5.0.6 的Ubuntu 14.04.3

,我运行Windows 10的机器

这里是我运行代码,我收到“错误:无法访问相机!” ..

请你帮忙!

// Get access to the webcam. 
void initWebcam(VideoCapture &videoCapture, int cameraNumber) 
{ 
    // Get access to the default camera. 
    try { 
     videoCapture.open(cameraNumber); 
    } catch (Exception &e) {} 
    if (!videoCapture.isOpened()) { 
     cerr << "ERROR: Could not access the camera!" << endl; 
     exit(1); 
    } 
    cout << "Loaded camera " << cameraNumber << "." << endl; 
} 

int main(int argc, char** argv) 
{ 

    const int DESIRED_CAMERA_WIDTH = 640; 
    const int DESIRED_CAMERA_HEIGHT = 480;  
    int cameraNumber = 0; 

    // Get access to the camera. 
    VideoCapture camera; 
    initWebcam(camera, cameraNumber); 

    camera.set(CV_CAP_PROP_FRAME_WIDTH, DESIRED_CAMERA_WIDTH); 
    camera.set(CV_CAP_PROP_FRAME_HEIGHT, DESIRED_CAMERA_HEIGHT); 

    while (true) { 

     // Grab the next camera frame. Note that you can't modify camera frames. 
     Mat cameraFrame; 
     camera >> cameraFrame; 
     if(cameraFrame.empty()) { 
      cerr << "ERROR: Couldn't grab the next camera frame." << endl; 
      exit(1); 
     } 

     Mat displayedFrame = Mat(cameraFrame.size(), CV_8UC3); 
     // DO SOME PROCESSING 

return 0; 
} 
+1

这应该回答。我也有同样的问题。 – userXktape

回答

0

我得到了同样的错误。这发生在我身上,因为我的虚拟机没有检测到我的摄像头。我已经安装了奶酪(一个使用网络摄像头的程序)并确认了这件事。所以,我打开虚拟机配置上的USB控制器。然后,运行虚拟机,我在设备菜单中检查了我的摄像头,并且所有的东西都开始工作了! 希望它有帮助。

0

这似乎是一个授权问题。 尝试从命令行运行sudo。 另一个问题可能是您选择了错误的相机(例如您有一台笔记本电脑,并且还有集成摄像头),您可以在连接到该虚拟机的设备上使用'dmesg | grep usb'

相关问题