Unchangeable OBS virtual camera default resolution
When using OBS to stream the video stream from an Android smartphone on an Apple laptop, it is impossible to correctly set the resolution of OBS's virtual camera with OpenCV.
By default, the resolution of OBS's virtual camera is set to 1080x1920, and it won't change according to OBS's output (scaled) resolution, or when calling OpenCV's set(cv2.CAP_PROP_FRAME_WIDTH,...) and set(cv2.CAP_PROP_FRAME_HEIGHT, ...) functions.
Yet, when retrieving the frames streamed by OBS's virtual camera, their shape now matches OBS's output resolution and not necessarily the advertised 1080x1920 resolution.
As a result, if OBS's output resolution is set to 640x480 and the camera's OpenCVCameraConfig set accordingly, the following width check in opencv.py:
if self.capture_width is not None and not math.isclose(
self.capture_width, actual_width, rel_tol=1e-3
):
will always raise an error :
OSError: Can't set self.capture_width=640 for OpenCVCamera(3). Actual value is 1920.0.
It indeed expects a width of self.capture_width=640 but will always get a width of actual_width=1920, even though the frames that would have been later received would have had the requested width.
This is kind of a niche issue, but worth to address if enough users encounter it !
Relevant versions
OBS - 31.0.3 MacOS - Sequoia 14.4.1 DroidCam - 7.3 Android 14 OpenCV - 4.11.0