Ask Your Question
1

VideoCapture select timeout with OpenCV 3.0.0-rc1

asked 2016-03-09 13:03:20 -0600

takahashi gravatar image

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;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-03-10 01:33:47 -0600

takahashi gravatar image

I found the problem: When using a webcam, make sure to connect it to the Virtual Machine using Devices->Webcams and NOT Devices->USB. Even though the webcam is detected as video0 when attaching it via Devices->USB, for some reasons it does not work.

edit flag offensive delete link more

Comments

How do I know "connect it to the Virtual Machine using Devices->Webcams" or change to it?

hoang anh tuan gravatar imagehoang anh tuan ( 2017-07-20 22:02:29 -0600 )edit

This worked for me. You need to check the top bar of Virtualbox and you'll see "Devices". Under "USB", nothing should be checked. Under "Webcams", make sure yours is checked. Verify with command "lsusb".

Void12987 gravatar imageVoid12987 ( 2019-10-16 09:43:12 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-09 13:03:20 -0600

Seen: 5,513 times

Last updated: Mar 10 '16