3

I'm trying to connect to several USB cameras that are connected to different USB buses (hopefully cancelling the bandwidth bottleneck caused by the USB). Before accessing to the cameras, I'm probing them with V4L2 API directly to see if they're accessible. For now, there are 3 cameras and V4L2 sees them all. Then I'm trying to access them using openCV like this, each in its own object:

this->camera = new cv::VideoCapture(camera_port);
if(this->camera->isOpened()) {
....
    cv::Mat capturedImage;
    bool read;
    read = this->camera->read(capturedImage);
....
}

where camera_port is 0,1,2. Obviously this->camera is called with release() on program closure.

The problem arises when I'm accessing more than 1 camera. Only one camera out of the three returns an image. The others return errors that I'm seeing on the console (not the same on every run):

  • libv4l2: error turning on stream: Connection timed out, VIDIOC_STREAMON: Connection timed out
  • libv4l2: error turning on stream: Input/output error, VIDIOC_STREAMON: Input/output error
  • libv4l2: error turning on stream: Invalid argument, VIDIOC_STREAMON: Invalid argument
  • Some other errors, but the above are the most frequent

However, this does work on the first run after replugging-in the USB cameras, but not on further runs of the program. Thoughts?

G. Ko
  • 403
  • 6
  • 15
  • 3
    Sounds like something is holding onto the cameras i.e. the app isn't actually closing what you think it is. Have you checked in processes (task manager) that the app is definitely closed? Also, you say release() is called on program close, It might be useful to create a small app that opens the cameras, shows and closes in one execution loop that you can use to test that when you plug them in the three different tasks are being conducted – GPPK Mar 05 '15 at 17:09
  • 1
    Maybe yor are not closing/releasing the cameras __inside__ V4L2 code? Make sure you do or try to not use this code(at least to test whether that causes the problem). Also try the following solutions: use release mode, use different camera numbers (4, 5, ..., 10), use different API (is you use 0-99 as a camera number OpenCV will choose API, to select API use number >= 100. List of possibiliteies: https://github.com/Itseez/opencv/blob/master/modules/videoio/src/cap.cpp#L124 ), try reinstalling/uninstalling drivers for all cameras. – cyriel Mar 05 '15 at 22:41
  • Well, the issue magically disappeared, or I can't trace back to the moment of fixing the issue. Thanks, guys. – G. Ko Mar 08 '15 at 13:38

0 Answers0