VideoCapture delayed for external webcam

Hi all - I’m getting started with OpenCV. I’m on Win11, Python3. When I run using my laptop’s built-in webcam, OpenCV gets going pretty quickly (averages under 300ms), when I switch to my USB-connected webcam, it takes about 18 seconds. I’m not sure if I need to set some different properties, but I’ve tinkered a bit and doesn’t seem to matter. I also notice it causes delay in reading frames later.

Simple code snippet:

milliseconds = int(time() * 1000)
logging.debug("1")
cap = cv2.VideoCapture(1)
logging.debug("2: %s ms", int(time() * 1000) - milliseconds)

Thoughts? Thanks in advance for any tips!

@lonb

Webcams drivers use to buffer images. When you read an image from the webcam, you are actually reading it from the buffer. If you don’t consume those images quickly enough (at the same rate they are produced) buffer will full, and then you will have to consume every image in the buffer before getting the actual one.

There’s no flush method, buffers size are unknown, may be different for each camera. The only recommendation is to read and discard some images before processing.