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()
FRAME_WIDTHat 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???