Multiple B0475 UVC 64MP Camera's cause CV2 timeout error

Hello,

I have 3 B0475 64MP cameras connected to my Raspberry Pi 5 via a high speed USB C 10/5Gbps hub.

When I run my python program to capture a frame (4623x3472) from just one camera it works fine, if i try and use 2 cameras it sometimes crashes and if I try and grab a frame from all 3 it crashes (after approx 9 cycles) with a CV2 timeout error. “VIDEOIO(V4L2:/dev/video0): select() timeout.”

it appears to me to be some sort of buffer being full.

I have included my code below, can anybody please help.

import cv2, os, sys, time
from datetime import datetime

os.system(“v4l2-ctl --list-devices > /mnt/ramdisk/usb-cameras”)
maicCameras = [“topCam”, “leftCam”, “rightCam”]
cameraCounter = 0
edgeCounter=0

with open(“/mnt/ramdisk/usb-cameras”) as file_object:
while True:
cameraLine = file_object.readline()
if (“Arducam B0475 (USB3 64MP)” in cameraLine):
video=file_object.readline()
video=video.strip()
print(video)
exec(“{} = cv2.VideoCapture("{}", cv2.CAP_V4L2)”.format(maicCameras[cameraCounter], video))
cameraCounter += 1
if cameraCounter == 3:
break
file_object.close()

exec(“topCam.set(cv2.CAP_PROP_FRAME_WIDTH, 4624)”)
exec(“topCam.set(cv2.CAP_PROP_FRAME_HEIGHT, 3472)”)
exec(“leftCam.set(cv2.CAP_PROP_FRAME_WIDTH, 4624)”)
exec(“leftCam.set(cv2.CAP_PROP_FRAME_HEIGHT, 3472)”)
exec(“rightCam.set(cv2.CAP_PROP_FRAME_WIDTH, 4624)”)
exec(“rightCam.set(cv2.CAP_PROP_FRAME_HEIGHT, 3472)”)

for i in range(3):

exec("{}.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(\"M\", \"J\", \"P\", \"G\"))".format(maicCameras[i]))

exec("{}.set(cv2.CAP_PROP_FOCUS, 320)".format(maicCameras[i]))
exec("{}.set(cv2.CAP_PROP_BUFFERSIZE, 10)".format(maicCameras[i]))
exec("{}.set(cv2.CAP_PROP_AUTO_WB, 1)".format(maicCameras[i]))
exec("{}.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1)".format(maicCameras[i]))

exec("{}.set(cv2.CAP_PROP_EXPOSURE, 100)".format(maicCameras[i]))
exec("{}.set(cv2.CAP_PROP_BRIGHTNESS, 0)".format(maicCameras[i]))
exec("{}.set(cv2.CAP_PROP_SATURATION, 10)".format(maicCameras[i]))
exec("{}.set(cv2.CAP_PROP_CONTRAST, 10)".format(maicCameras[i]))

while True:
print(“\n{}\tStill Running - Program looped {} times”.format(datetime.now().strftime(“%d/%m/%Y %H:%M:%S”), edgeCounter))

# topCam Capture
time.sleep(2)
frameCaptured = False
captureCounter = 0
stillRunning = True
print("Top Camera Capturing...", end="\r")
while not frameCaptured:
    frameCaptured, fullPiP = topCam.read()
    captureCounter += 1
    if captureCounter == 2:
        print("No Frame Returning - Program looped {} times".format(edgeCounter))
        stillRunning = False
print("Top Camera Captured     ")
cv2.imwrite("/mnt/ramdisk/topCam.jpg", fullPiP)
    
# leftCam Capture
time.sleep(2)
frameCaptured = False
captureCounter = 0
stillRunning = True
print("Left Camera Capturing...", end="\r")
while not frameCaptured:
    frameCaptured, fullPiP = leftCam.read()
    captureCounter += 1
    if captureCounter == 2:
        print("No Frame Returning - Program looped {} times".format(edgeCounter))
        stillRunning = False
print("Left Camera Captured     ")
#cv2.imwrite("/mnt/ramdisk/leftCam.jpg", leftImage)
    
# rightCam Capture
time.sleep(2)
frameCaptured = False
captureCounter = 0
stillRunning = True
print("Right Camera Capturing...", end="\r")
while not frameCaptured:
    frameCaptured, fullPiP = rightCam.read()
    captureCounter += 1
    if captureCounter == 2:
        print("No Frame Returning - Program looped {} times".format(edgeCounter))
        stillRunning = False
print("Right Camera Captured     ")
            
if stillRunning:
    edgeCounter += 1