System designHow-to

How to open and enumerate multiple USB cameras in one Python SDK

Enumerate every USB camera from your SDK's device list, open one session per serial, and budget USB 3.0 bandwidth so two raw streams run at full rate.

LumaSpec Vision10 min read Share on LinkedIn

On this page 7 sections
  1. 01What you need
  2. 02Enumerate, open and keep one session per camera
    1. Verify the mapping with your hand
    2. Verify the frame rate
  3. 03The bandwidth budget that decides how many cameras fit
  4. 04When both cameras will not fit
  5. 05Common mistakes
  6. 06Quick checklist
  7. 07Questions

Your SDK's demo opens one camera, and it works until the second one goes on the bus: the example grabs from whichever device it finds first, or the second open call fails. The fix is two things. An enumerate-and-open pattern keyed on each camera's unique ID, kept in your own dictionary, so two cameras — or ten — open in a known order with known handles. And the USB 3.0 bandwidth arithmetic that decides how many of those cameras run at full frame rate on one bus, because bandwidth, not a camera count, is the limit.

What you need

Everything below assumes you have:

  • Two or more USB 3.0 cameras that deliver raw Bayer or raw mono frames. Compact board-level cameras suit an OEM head; housed area scan cameras suit the bench.
  • One USB 3.0-rated cable per camera. A charge-only cable silently caps the link at USB 2.0 speed.
  • A host where the cameras land on separate buses when you need two full budgets: desktop rear-panel ports usually hang off different controllers, while front-panel and display-adjacent ports often share an internal hub.
  • The SDK's Python package installed, with the single-camera example running first. Get one camera solid before you scale.
  • Your pixel format decision written down — RAW8, packed RAW10 or a 16-bit container — because bytes per pixel drives the bandwidth budget below.

Two USB 3.0 cameras of the kind this pattern suits, one board-level and one housed:

Board-level cameras3.1 MP USB3 board-level camera, IMX252, 1/1.8" global shutter, 120 fps (LS-BCM-0003)LS-BCM-0003
Sensor format
1/1.8"
Lens mount
C-mount
$690.00View part
Area scan camerasHikrobot MV-CT0MU0060/R/NN/NN 6 MP Area Scan Camera, 3rd Gen., USB3.0, Mono, BASEMV-CT0MU0060/R/NN/NN
Sensor format
1/1.8"
Lens mount
C-mount
$969.00View part

Enumerate, open and keep one session per camera

Every camera SDK — GenICam-based or an embedded board's own library — exposes the same three capabilities: enumerate devices, each with a unique ID; open one session per ID; grab from a session. Only the call names change. These six steps keep the order right.

  1. Enumerate from the SDK first. Call the device enumerator before anything else and print every entry with its unique ID — the serial number or bus path. Your OS's device manager lists devices too, but the ID your open call needs is the one the SDK prints, and the two lists do not always agree.
  2. Key on the unique ID, never the list index. Indexes reorder after a replug or a reboot; serials do not. Two identical cameras differ only by serial, and if yours report the same name, the identical USB cameras fix opens one by its bus port instead.
  3. Keep your own dictionary. One dict, ID to session, initialized empty before the loop. It is your rescan guard: a camera already in the dict is never opened twice.
  4. Open one session per ID. Pass the ID to the SDK's open call inside the loop. Most SDKs refuse to open the same device twice; the dict makes that explicit instead of incidental.
  5. Set format, exposure and gain per session. In most SDKs those settings live on the session handle, so apply them inside the loop, not once globally.
  6. Assert before you stream. The number of open sessions must equal the number of detected devices.
# Illustrative names: substitute your SDK's own enumerate and open calls.
# sessions: dict[str, Camera], initialized empty
sessions = {}
devices = sdk.enumerate_devices()          # list, one descriptor per camera

for dev in devices:
    ident = dev.unique_id                  # serial number or bus path
    if ident not in sessions:              # rescan guard
        sessions[ident] = Camera.open(ident)   # by ID, never by index

# The test that proves the result:
assert len(devices) == len(sessions)       # every detected camera is open
assert len(sessions) == 2                  # two plugged in -> two sessions

# One grab per session, tagged with the ID that owns it:
frames = {ident: cam.get_image() for ident, cam in sessions.items()}

Keep the assert lines in your code. The day a third camera joins, or one cable works loose, the assertion fires at start-up instead of quietly dropping frames all shift.

Verify the mapping with your hand

Start the grab loop, log every frame with the session ID that produced it, then cover one lens with your hand. The dark frames must carry the covered camera's ID. If they carry the other one, something in your code still opens by index — fix it now, because a swapped mapping costs far more to debug after deployment than at the bench.

Verify the frame rate

Count frames per session over ten seconds and divide by ten. Either camera alone should sit at its mode's rated rate. If both together settle well below it while either alone is fine, you have saturated the bus, and the next section tells you by how much.

The bandwidth budget that decides how many cameras fit

One USB 3.0 bus carries 5 Gbit/s on the wire. 8b/10b encoding consumes 20% of that, which leaves 500 MB/s of raw payload, and protocol and driver overhead leave applications roughly 400 MB/s, 450 MB/s at best (USB 3.0 on Wikipedia). Plan on 400 MB/s.

bytes per frame = width × height × bytes per pixel per-camera rate (MB/s) = bytes per frame × fps ÷ 1,000,000 rule: the sum over all cameras on one USB 3.0 bus stays under 400 MB/s bytes per pixel: RAW8 = 1.00 · RAW10 packed = 1.25 · RAW12 packed = 1.50 · 16-bit container = 2.00

MB/s here is decimal megabytes, 10^6 bytes per second — the unit USB throughput is quoted in. The bytes per pixel that counts is the delivered format your session reports, not the sensor's own bit depth.

Take a typical 5 MP sensor at 2592 × 1944, two cameras, 30 fps each.

RAW8: 2592 × 1944 × 1.00 B = 5,038,848 B ≈ 5.04 MB per frame. Per camera: 5.04 × 30 = 151.2 MB/s. Both: 302.4 MB/s against a 400 MB/s budget — both run full rate with about 98 MB/s spare.

16-bit container: 2592 × 1944 × 2.00 B = 10,077,696 B ≈ 10.08 MB per frame. Per camera at 30 fps: 302.4 MB/s; both: 604.8 MB/s, half again over budget. The frame-rate cap per camera is 400 ÷ (2 × 10.08) = 19.8 fps, so set 19: 10.08 × 19 × 2 = 383.0 MB/s, which fits with 4% spare.

Delivered format Bytes per pixel 5 MP frame Two cameras at 30 fps Verdict on one bus
RAW8 1.00 5.04 MB 302.4 MB/s Fits, 24% spare
RAW10 packed 1.25 6.30 MB 378.0 MB/s Fits with 5% spare; no room for a third camera
RAW12 packed 1.50 7.56 MB 453.6 MB/s Over budget; 26 fps each is the cap
16-bit container 2.00 10.08 MB 604.8 MB/s Over budget; 19 fps each is the cap

The same division scales up. A 12 MP sensor at 4000 × 3000 moves 4000 × 3000 × 1.00 B = 12.0 MB per RAW8 frame, so one camera of that class at 30 fps draws 12.0 × 30 = 360 MB/s — 90% of the entire budget alone. Two at that mode never share a bus; give the second camera a second controller or halve the frame rate. The LS-CMR-0166 sits in exactly that class: 12 MP at 4000 × 3000 and 30 fps.

Area scan cameras12 MP USB3 area scan camera, IMX226, 1/1.7" rolling shutter, 30 fps, 4000 × 3000 resolution (LS-CMR-0166)LS-CMR-0166
Sensor format
1/1.7"
Interface
USB3
Resolution
12 MP
Shutter
Rolling
$560.00View partBuild a system with it

This budget is per bus, not per port. An external hub — however many ports it shows — carries one upstream 5 Gbit/s link, so two cameras on the same hub share one 400 MB/s. The USB hub frame-rate failure is precisely that budget spent from two ports at once. To double the budget, add a PCIe USB 3.0 controller card and put one camera on each controller.

When both cameras will not fit

Four moves, in the order to try them:

  1. Cut frame rate. The effect is linear: fps per camera = 400 ÷ (camera count × MB per frame). For the two 16-bit cameras above that is 19.8, so 19 fps each.
  2. Pack the pixels. Moving a 10-bit stream from a 16-bit container to packed RAW10 cuts bytes per pixel from 2.00 to 1.25, a 37.5% reduction — often enough to restore full frame rate without touching anything else. Pack only if your algorithm tolerates it: RAW8 throws away the top stops, and 16-bit containers do not always span 0–65535 — 12-bit data in a 16-bit V4L2 frame shows the classic case.
  3. Add a bus, not a port. A PCIe USB 3.0 controller card brings its own 400 MB/s. A hub brings none.
  4. Give one camera its own wire. A GigE camera has roughly 115 MB/s of payload with jumbo frames — about a quarter of a USB 3.0 bus — but it never competes with the USB budget. If shared buses keep forcing these trade-offs, the same shared-wire versus networked decision is laid out in this USB webcams versus IP cameras comparison.

Decisions for the worked example: two 5 MP cameras in RAW8 at 30 fps — run both on one bus as-is. The same two in 16-bit containers — set 19 fps each, or pack to RAW10 and keep 30, or add a second controller. One 12 MP camera at 30 fps RAW8 — give it the bus alone.

Common mistakes

  • Blocking grabs and per-frame writes in the consumer. If both sessions crawl while the bus has headroom, the bottleneck is your loop, not the wire — the Python camera GUI low-FPS fix walks through the two usual culprits.
  • Synchronizing with sleep loops. Starting two sessions with a timed offset drifts by milliseconds within minutes. For frames that share a timestamp, feed both cameras the same hardware trigger — triggering two USB cameras together shows the wiring and the call pattern.
  • Shrinking the ROI and forgetting the budget. Halving width halves the sum; widening it back doubles it again. Recompute the bandwidth sum every time width, height, pixel depth or fps changes — at design time and after any firmware update that adds or alters a mode.

Quick checklist

Before you wire:

  • Sum width × height × bytes per pixel × fps over every camera on a bus; the total stays under 400 MB/s.
  • Confirm the host actually has one bus per full budget: separate controllers, not two ports of one hub.
  • If two cameras must share a hub, the hub is self-powered.

Before you run the code:

  • Enumerated and printed every unique ID; sessions keyed on IDs in a dict initialized empty.
  • Assert open sessions equal detected devices.
  • Format, exposure and gain applied per session.

First hour of running:

  • Hand-over-lens test: the dark frames carry the covered camera's ID.
  • Ten-second fps count per session; both together sit at the cap the budget predicts.

To pick the cameras before writing any of this, the camera finder filters by interface and resolution, the configurator starts at the camera step, and the learn hub holds the rest of the integration guides. If you send us your sensor, pixel format and frame rate before ordering, the bandwidth answer is one division away — contact us.

Questions

How do I open two identical USB cameras that report no serial number?

Open by the bus port path instead of the serial: the OS builds a stable address from the physical connector chain — controller, hub, port — so the same socket always maps to the same path. Label cables and sockets, because swapping plugs swaps the mapping. If your SDK exposes only indexes, plug cameras in one at a time and record which index each socket produced before writing the opening code.

How many USB cameras can one host controller run?

Divide the bus budget by each camera's stream: 400 MB/s ÷ per-camera MB/s. Six 1.6 MP cameras (1600 × 1200) in RAW8 at 30 fps draw 1.92 MB × 30 = 57.6 MB/s each, so about six fit one bus. The same six in a 16-bit container draw 115.2 MB/s each and only three fit. The count comes from the arithmetic, not from a listed maximum.

Does 10-bit data double the bandwidth compared with 8-bit?

Only if the SDK unpacks it. Packed RAW10 carries four pixels in five bytes, 1.25 bytes per pixel — 25% more than RAW8. Unpacked formats park each value in a 16-bit word, 2.0 bytes per pixel — double. Read the pixel format string your session reports; the delivered bytes per pixel, not the sensor's bit depth, is what enters the bandwidth sum.

Why does the second camera fail to open while the first is streaming?

An open session owns the device exclusively, so a second handle on the same camera fails or steals frames — and it usually means the code opened by index twice instead of by two different IDs. Close the first session, re-enumerate, and confirm the two IDs differ before opening again. A viewer or capture tool left running holds the same exclusive lock; quit it first.