Free Motion Capture for Everyone πβ¨
TypeScript
fix imports, add camera calibration file for jon
Endurance Idehen86567f0cf3e2
diff --git a/src/api/routes/camera/cam_data_ws.py b/src/api/routes/camera/cam_data_ws.pyindex 6d82f9d1..f2eb25ea 100644--- a/src/api/routes/camera/cam_data_ws.py+++ b/src/api/routes/camera/cam_data_ws.py@@ -6,7 +6,7 @@ from fastapi import APIRouter, WebSocketfrom src.api.services.board_detect_service import BoardDetectServicefrom src.api.services.mediapipe_detect_service import MediapipeSkeletonDetectionService-from src.cameras.multicam_manager import CVCameraManager+from src.cameras.multicam_manager.cv_camera_manager import CVCameraManagerlogger = logging.getLogger(__name__)diff --git a/src/api/services/mediapipe_detect_service.py b/src/api/services/mediapipe_detect_service.pyindex f9a624a3..87b4b234 100644--- a/src/api/services/mediapipe_detect_service.py+++ b/src/api/services/mediapipe_detect_service.py@@ -1,4 +1,4 @@-from src.cameras.multicam_manager import CVCameraManager+from src.cameras.multicam_manager.cv_camera_manager import CVCameraManagerfrom src.core_processor.mediapipe_skeleton_detection.mediapipe_skeleton_detection import (MediapipeSkeletonDetection,)diff --git a/src/cameras/capture/opencv_camera/opencv_camera.py b/src/cameras/capture/opencv_camera/opencv_camera.pyindex 084876ba..a7a8fd0d 100644--- a/src/cameras/capture/opencv_camera/opencv_camera.py+++ b/src/cameras/capture/opencv_camera/opencv_camera.py@@ -33,12 +33,11 @@ class OpenCVCamera:Performant implementation of video capture against webcams"""- _opencv_video_capture_object: cv2.VideoCapture = None- _running_thread: FrameThread = None-def __init__(self, config: WebcamConfig):self._config = configself._name = f"Camera {self._config.webcam_id}"+ self._opencv_video_capture_object: cv2.VideoCapture = None+ self._running_thread: FrameThread = None@propertydef webcam_id_as_str(self):diff --git a/src/cameras/multicam_manager/cv_camera_manager.py b/src/cameras/multicam_manager/cv_camera_manager.pyindex c45fba71..1ac6a432 100644--- a/src/cameras/multicam_manager/cv_camera_manager.py+++ b/src/cameras/multicam_manager/cv_camera_manager.py@@ -30,7 +30,7 @@ class CVCameraManager:global _cv_camsif _cv_cams is None:logger.info("Creating cams.")- # we create the _cv_cams once, and reuse it for the lifetime of the session+ # we create the _cv_cams /once/, and reuse it for the lifetime of the session_cv_cams = self._create_opencv_cams()self._cv_cams = _cv_camselse:diff --git a/src/core_processor/board_detection/board_detection.py b/src/core_processor/board_detection/board_detection.pyindex 0ba377c5..36a91f28 100644--- a/src/core_processor/board_detection/board_detection.py+++ b/src/core_processor/board_detection/board_detection.py@@ -2,6 +2,8 @@ import loggingimport timeimport tracebackfrom pathlib import Path+from types import FunctionType+from typing import Any, Callable, Optionalimport cv2import numpy as np@@ -14,6 +16,7 @@ from src.core_processor.board_detection.charuco_image_annotator import (annotate_image_with_charuco_data,)from src.core_processor.fps.fps_counter import FPSCamCounter+from src.core_processor.show_cam_window import show_cam_windowfrom src.core_processor.utils.image_fps_writer import write_fps_to_imagelogger = logging.getLogger(__name__)@@ -61,7 +64,9 @@ class BoardDetection:)writer.save(options)- def process(self):+ def process(+ self, show_window=True, post_processed_frame_cb=Callable[[FramePayload], None]+ ):"""Opens Camera using OpenCV and begins image processing for charuco boardIf return images is true, the images are returned to the caller@@ -72,11 +77,8 @@ class BoardDetection:fps_manager = FPSCamCounter(self._cam_manager.available_webcam_ids)fps_manager.start_all()try:- while True:- exit_key = cv2.waitKey(1)- if exit_key == 27:- logger.info("ESC has been pressed.")- break+ should_continue = True+ while should_continue:for response in session_obj:cv_cam = response.cv_camwriter = response.writer@@ -85,12 +87,14 @@ class BoardDetection:if payload is not None:writer.write(payload)+ if post_processed_frame_cb:+ post_processed_frame_cb(payload)+fps_manager.increment_frame_processed_for(current_webcam_id)- write_fps_to_image(- payload.image,- fps_manager.current_fps_for(current_webcam_id),- )- cv2.imshow(current_webcam_id, payload.image)+ if show_window:+ should_continue = show_cam_window(+ current_webcam_id, payload.image, fps_manager+ )except:logger.error("Printing traceback")traceback.print_exc()diff --git a/src/core_processor/camera_calibration/camera_calibration.py b/src/core_processor/camera_calibration/camera_calibration.pynew file mode 100644index 00000000..14004ba0--- /dev/null+++ b/src/core_processor/camera_calibration/camera_calibration.py@@ -0,0 +1,22 @@+from src.cameras.capture.frame_payload import FramePayload+from src.core_processor.board_detection.board_detection import BoardDetection+++class CameraCalibration:+ def __init__(self, board_detection: BoardDetection):+ self._bd = board_detection++ def perform_calibration(self):+ self._bd.process(+ show_window=True,+ post_processed_frame_cb=self._calibration_work,+ )++ def _calibration_work(self, frame: FramePayload):+ print("found frame", frame.timestamp)+++if __name__ == "__main__":+ a = BoardDetection()+ b = CameraCalibration(a)+ b.perform_calibration()diff --git a/src/core_processor/show_cam_window.py b/src/core_processor/show_cam_window.pynew file mode 100644index 00000000..bb7f712d--- /dev/null+++ b/src/core_processor/show_cam_window.py@@ -0,0 +1,23 @@+import logging++import cv2+import numpy as np++from src.core_processor.fps.fps_counter import FPSCamCounter+from src.core_processor.utils.image_fps_writer import write_fps_to_image++logger = logging.getLogger(__name__)+++def show_cam_window(webcam_id: str, image: np.array, fps_counter_cls: FPSCamCounter):+ exit_key = cv2.waitKey(1)+ if exit_key == 27:+ logger.info("ESC has been pressed.")+ return False++ write_fps_to_image(+ image,+ fps_counter_cls.current_fps_for(webcam_id),+ )+ cv2.imshow(webcam_id, image)+ return True