From 40f970130fd3a91a521795ebdce5d5fdb315644d Mon Sep 17 00:00:00 2001 From: williamwadsworth Date: Thu, 26 Feb 2026 14:02:03 +0000 Subject: [PATCH] human readable opencv camera names in windows --- .../things/camera/opencv_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/openflexure_microscope_server/things/camera/opencv_utils.py b/src/openflexure_microscope_server/things/camera/opencv_utils.py index 160d50a3..d93decd2 100644 --- a/src/openflexure_microscope_server/things/camera/opencv_utils.py +++ b/src/openflexure_microscope_server/things/camera/opencv_utils.py @@ -3,6 +3,7 @@ import sys import cv2 +from cv2_enumerate_cameras import enumerate_cameras if sys.platform.startswith("win"): BACKEND = cv2.CAP_DSHOW @@ -44,5 +45,13 @@ def identify_cameras(camera_ids: list[int]) -> dict[str, int]: name_dict[camera_id] = f_obj.read().strip() except IOError: pass + + if BACKEND == cv2.CAP_DSHOW: + try: + for camera_info in enumerate_cameras(cv2.CAP_DSHOW): + name_dict[camera_info.index] = camera_info.name + except IOError: + pass + # Swap order for return return {name: cam_id for cam_id, name in name_dict.items()}