2015-11-04 147 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'

相關問題