Free Motion Capture for Everyone πβ¨
TypeScript
Jon/sesh setup screen (#245)
jonmatthis627fa8bd5560
diff --git a/src/cameras/detection/cam_detection.py b/src/cameras/detection/cam_detection.pyindex 712ccb84..00dd9076 100644--- a/src/cameras/detection/cam_detection.py+++ b/src/cameras/detection/cam_detection.py@@ -1,7 +1,9 @@import loggingimport platform+import timeimport cv2+import numpy as npfrom src.cameras.detection.models import FoundCamerasResponse@@ -15,17 +17,45 @@ class DetectPossibleCameras:cv2_backend = self._determine_backend()cams_to_use_list = []+ caps_list = []for cam_id in range(CAM_CHECK_NUM):cap = cv2.VideoCapture(cam_id, cv2_backend)success, image = cap.read()+ time0 = time.perf_counter()if success:if image is not None:try:- logger.debug(f"Camera found at port number {cam_id}")+ success, image = cap.read()+ time1 = time.perf_counter()++ if time1 - time0 > 0.5:+ logger.debug(+ f"Camera {cam_id} took {time1-time0} seconds to produce a 2nd frame. It might be a virtual camera Skipping it."+ )+ continue # skip to next port number++ logger.debug(+ f"Camera found at port number {cam_id}: success={success}, image.shape={image.shape}, cap={cap}"+ )cams_to_use_list.append(str(cam_id))- finally:- cap.release()+ caps_list.append(cap)++ # # # for debugging - uncomment to show cameras as they are detected+ # while True:+ # cv2.imshow(f"Camera {cam_id} - press 'q' to continue", image)+ # if cv2.waitKey(1) & 0xFF == ord('q'):+ # break+ # success, image = cap.read()++ except Exception as e:+ logger.error(+ f"Exception raised when looking for a camera at port{cam_id}: {e}"+ )++ for cap in caps_list:+ logger.debug(f"Releasing cap {cap}")+ cap.release()return FoundCamerasResponse(number_of_cameras_found=len(cams_to_use_list),