Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoCapture select timeout with OpenCV 3.0.0-rc1

I am using OpenCV 3.0.0-rc1 on Ubuntu 14.04 LTS Guest in VirtualBox with Windows 8 Host. I have an extremely simple program to read in frames from a webcam (Logitech C170) (from the OpenCV documentation). Unfortunately, it doesn't work (I have tried 3 different webcams). It throws an error "select timeout" every couple of seconds and reads a frame, but the frame is black. Any ideas?

The code is the following:

#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;
}