2

I'm using OpenCV-Python on Windows 11 to capture video from a USB camera for object detection tasks. However, I noticed that the camera’s frame rate is extremely low — maybe only about 1 FPS, even though the camera officially supports MJPG 1920×1080 @ 60FPS. On Ubuntu 20.04, the same camera works perfectly with the expected high frame rate.

While searching online, I found an odd workaround: Instead of setting the resolution directly to 1920×1080, if I set it to something like 1900×1080, the program automatically picks the nearest valid resolution (still outputs 1920×1080 frames) — but suddenly, the delay drops dramatically and the frame rate becomes normal.
I don’t understand why this happens on Windows but not on Linux.
Could someone explain the underlying reason for this behavior?

import cv2

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG"))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1900)  # if set 1920, it's very slow 
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
cap.set(cv2.CAP_PROP_FPS, 60)

while True:
    ret, frame = cap.read()
    if not ret:
        break
    cv2.imshow("camera", frame)
    if cv2.waitKey(1) == 27:
        break

cap.release()
cv2.destroyAllWindows()
5
  • 3
    oh a fun driver bug maybe? Commented Nov 1 at 0:08
  • It might be worth tracing into the set FRAME_WIDTH at assembler level to see how the 1900 is rounded up to 1920. Looks like a Win driver bug to me. Or it could be one of the other set commands afterwards that goes wrong. FPS ??? Commented Nov 1 at 8:38
  • don't mess around like that. it's slow because setting FOURCC to MJPG didn't "take" properly. vary the order of set() calls. try setting the FOURCC last. that can have an effect. Commented Nov 1 at 13:23
  • After setting these parameters, I called cap.get(...) to check if they were actually applied.However, on Windows, other parameters like FPS and resolution can be retrieved correctly,but cv2.CAP_PROP_FOURCC always returns some strange or unexpected value. So I can’t be sure whether MJPG was successfully applied or if the camera is still using a low-frame-rate format like YUYV. Commented Nov 1 at 17:34
  • get() on FOURCC should return a number. post the numbers you get. Commented Nov 1 at 18:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.