我試圖使用我的計算機上的攝像頭實時捕獲圖像。 我使用虛擬盒子運行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;
}
這應該回答。我也有同樣的問題。 – userXktape