Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

better handling of opening and closing camera resources as well as thread resources

Endurance Idehen23e7ab407c29
diff --git a/src/api/routes/camera/cam_data_ws.py b/src/api/routes/camera/cam_data_ws.py
index d3b6549a..3ee750f6 100644
--- a/src/api/routes/camera/cam_data_ws.py
+++ b/src/api/routes/camera/cam_data_ws.py
@@ -24,11 +24,6 @@ class MyEncoder(json.JSONEncoder):
return json.JSONEncoder.default(self, obj)
-@cam_ws_router.post("/start_realtime_capture")
-async def start_realtime_capture():
- pass
-
-
@cam_ws_router.get("/begin_board_detection")
async def begin_board_detection():
service = BoardDetectService()
diff --git a/src/cameras/opencv_camera.py b/src/cameras/opencv_camera.py
index 12a5eda7..67009776 100644
--- a/src/cameras/opencv_camera.py
+++ b/src/cameras/opencv_camera.py
@@ -90,12 +90,14 @@ class OpenCVCamera:
def start_frame_capture(self):
if self.is_capturing_frames:
- logger.info(
+ logger.debug(
f"Already capturing frames for webcam_id: {self.webcam_id_as_str}"
)
return
+ logger.info(
+ f"Beginning frame capture thread for webcam: {self.webcam_id_as_str}"
+ )
self._running_thread = self._create_thread()
- print(f"Is this thread alive? {self._running_thread.is_alive()}")
self._running_thread.start()
def _create_thread(self):
@@ -131,7 +133,7 @@ class OpenCVCamera:
self._running_thread.stop()
while self._running_thread.is_alive():
# wait for thread to die.
- # TODO: use event?
+ # TODO: use threading.Event for synchronize mainthread vs other threads
time.sleep(0.1)
self._opencv_video_capture_object.release()
logger.info("Closed {}".format(self._name))
diff --git a/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.py b/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.py
index 881643cf..e4b2e33c 100644
--- a/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.py
+++ b/src/core_processor/mediapipe_skeleton_detection/mediapipe_skeleton_detection.py
@@ -50,16 +50,19 @@ class MediapipeSkeletonDetection:
while True:
exit_key = cv2.waitKey(1)
if exit_key == 27:
- cv2.destroyAllWindows()
- close_all_cameras(cv_cams)
+ logger.info("ESC has been pressed.")
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)
except:
- close_all_cameras(cv_cams)
- cv2.destroyAllWindows()
- cv2.waitKey(1)
+ logger.error("Printing traceback")
+ traceback.print_exc()
+ finally:
+ for cv_cam in cv_cams:
+ logger.info(f"Destroy window {cv_cam.webcam_id_as_str}")
+ cv2.destroyWindow(cv_cam.webcam_id_as_str)
+ cv2.waitKey(1)
def _process_single_cam_frame(self, holistic, cv_cam):
success, frame, timestamp = cv_cam.latest_frame