【问题标题】:VideoCapture select timeout with OpenCV 3.0.0-rc1使用 OpenCV 3.0.0-rc1 的 VideoCapture 选择超时
【发布时间】:2016-03-10 07:08:29
【问题描述】:

我在带有 Windows 8 主机的 VirtualBox 中的 Ubuntu 14.04 LTS Guest 上使用 OpenCV 3.0.0-rc1。我有一个非常简单的程序来读取来自网络摄像头(Logitech C170)的帧(来自 OpenCV 文档)。不幸的是,它不起作用(我尝试了 3 种不同的网络摄像头)。它每隔几秒钟抛出一个错误“选择超时”并读取一帧,但该帧是黑色的。有什么想法吗?

代码如下:

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace std;
using namespace cv;

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

/* webcam setup */
VideoCapture stream;
stream.open(0);
// check if video device has been initialized
if (!stream.isOpened()) { 
        fprintf(stderr, "Could not open Webcam device");  
        return -1;
    }
    int image_width = 640; // image resolution
    int image_height = 480;
    Mat colorImage,currentImage;
    bool loop = true;
    /* infinite loop for video stream */
    while (loop) {
        loop = stream.read(colorImage);  // read webcam stream
        cvtColor(colorImage, currentImage, CV_BGR2GRAY); // color to gray for current image   
        imshow("Matches", currentImage);
        if(waitKey(30) >= 0) break;
        // end stream while-loop
    }
    return 0;
}

【问题讨论】:

    标签: c++ opencv webcam video-capture webcam-capture


    【解决方案1】:

    我发现了问题:使用网络摄像头时,请确保使用Devices-&gt;Webcams 而不是Devices-&gt;USB 将其连接到虚拟机。即使通过Devices-&gt;USB 附加网络摄像头时检测到video0,但由于某些原因它无法正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-16
      • 2012-10-05
      • 1970-01-01
      • 2016-12-15
      • 2012-09-24
      • 2015-08-12
      • 2015-10-18
      相关资源
      最近更新 更多