Skip to content
Advertisement

Capturing video from two cameras in OpenCV at once

How do you capture video from two or more cameras at once (or nearly) with OpenCV, using the Python API?

I have three webcams, all capable of video streaming, located at /dev/video0, /dev/video1, and /dev/video2.

Using the tutorial as an example, capturing images from a single camera is simply:

JavaScript

And this works fine.

However, if I try to initialize a second camera, attempting to read() from it returns None:

JavaScript

Just to ensure I wasn’t accidentally giving OpenCV a bad camera index, I tested each camera index individually and they all work by themselves. e.g.

JavaScript

What am I doing wrong?

Edit: My hardware is a Macbook Pro running Ubuntu. Researching the issue specifically on Macbooks, I’ve found others that have run into this problem too, both on OSX and with different types of cameras. If I access the iSight, both calls in my code fail.

Advertisement

Answer

Yes you’re definitely limited by the USB bandwidth. Attempting to read from both devices at full-rez you probably got error:

JavaScript

And then when you reduce the res to 160×120:

JavaScript

now it seems to work! I bet you have both cams connected on the same USB card. You can run lsusb command to make sure, and it should indicate something like:

JavaScript

(Note both cameras on same bus.) If possible, you can add another USB card to your machine to gain more bandwidth. I’ve done this before in order to run multiple cams at full resolution on a single machine. Albeit that was a tower workstation with available motherboard slots, and unfortunately you may not have that option on a MacBook laptop.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement