Free Motion Capture for Everyone πβ¨
TypeScript
safety, close windows easily
Endurance Idehen3230920695a0
diff --git a/src/cameras/cam_factory.py b/src/cameras/cam_factory.pyindex 905eced7..357d6c25 100644--- a/src/cameras/cam_factory.py+++ b/src/cameras/cam_factory.py@@ -1,3 +1,5 @@+from typing import List+from src.cameras.cam_singleton import get_or_create_camsfrom src.cameras.opencv_camera import OpenCVCamera, WebcamConfig@@ -17,3 +19,8 @@ def create_opencv_cams():for cv_cam in cv_cams:cv_cam.connect()return cv_cams+++def close_all_cameras(cv_cams: List[OpenCVCamera]):+ for cv_cam in cv_cams:+ cv_cam.close()diff --git a/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.py b/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.pyindex 42ce5c33..c7065781 100644--- a/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.py+++ b/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.py@@ -5,7 +5,7 @@ import tracebackimport cv2import mediapipe as mp-from src.cameras.cam_factory import create_opencv_cams+from src.cameras.cam_factory import close_all_cameras, create_opencv_camsfrom src.core_processor.utils.image_fps_writer import write_fps_to_imagemp_holistic = mp.solutions.holistic@@ -26,16 +26,15 @@ class MediapipeSkeletonDetection:min_tracking_confidence=0.5,model_complexity=0,) as holistic:- while True:- try:+ try:+ while True:for cv_cam in cv_cams:image = self._process_single_cam_frame(holistic, cv_cam)if cb:await cb(image, cv_cam.webcam_id_as_str)- except:- for cv_cam in cv_cams:- cv_cam.close()- traceback.print_exc()+ except:+ close_all_cameras(cv_cams)+ traceback.print_exc()async def process(self):cv_cams = create_opencv_cams()@@ -48,16 +47,19 @@ class MediapipeSkeletonDetection:min_tracking_confidence=0.5,model_complexity=0,) as holistic:- while True:- exit_key = cv2.waitKey(1)- if exit_key == 27:- cv2.destroyAllWindows()+ try:+ while True:+ exit_key = cv2.waitKey(1)+ if exit_key == 27:+ cv2.destroyAllWindows()+ close_all_cameras(cv_cams)+ breakfor cv_cam in cv_cams:- cv_cam.close()- break- for cv_cam in cv_cams:- image = self._process_single_cam_frame(holistic, cv_cam)- cv2.imshow(cv_cam.webcam_id_as_str, image)+ image = self._process_single_cam_frame(holistic, cv_cam)+ cv2.imshow(cv_cam.webcam_id_as_str, image)+ except:+ close_all_cameras(cv_cams)+ cv2.destroyAllWindows()def _process_single_cam_frame(self, holistic, cv_cam):success, frame, timestamp = cv_cam.latest_frame