Free Motion Capture for Everyone πβ¨
TypeScript
refactor
Endurance Idehen1e7b08be61cc
diff --git a/src/cameras/cam_detection.py b/src/cameras/cam_detection.pyindex ca94f124..a1edcf64 100644--- a/src/cameras/cam_detection.py+++ b/src/cameras/cam_detection.py@@ -15,18 +15,18 @@ class DetectPossibleCameras:cv2_backend = self._determine_backend()cams_to_use_list = []- for camNum in range(CAM_CHECK_NUM):- cap = cv2.VideoCapture(camNum, cv2_backend)+ for cam_id in range(CAM_CHECK_NUM):+ cap = cv2.VideoCapture(cam_id, cv2_backend)success, image = cap.read()if success:logger.info(- f"camera at port {camNum} found an image with shape {image.shape}"+ f"camera at port {cam_id} found an image with shape {image.shape}")try:cams_to_use_list.append(RawCamera(- port_number=camNum,+ webcam_id=cam_id,))finally:diff --git a/src/cameras/opencv_camera.py b/src/cameras/opencv_camera.pyindex cda8cd2f..f9854503 100644--- a/src/cameras/opencv_camera.py+++ b/src/cameras/opencv_camera.py@@ -36,7 +36,7 @@ class OpenCVCamera(BaseModel):@propertydef webcam_id_as_str(self):- return self.webcam_id_as_str+ return str(self.webcam_id)@propertydef current_fps(self):diff --git a/src/core_processor/board_detection/charuco_image_annotator.py b/src/core_processor/board_detection/charuco_image_annotator.pyindex ce461ec5..2a6ee3e0 100644--- a/src/core_processor/board_detection/charuco_image_annotator.py+++ b/src/core_processor/board_detection/charuco_image_annotator.py@@ -1,28 +1,52 @@+from typing import List+import cv2import numpy as npfrom src.core_processor.board_detection.charuco_constants import num_charuco_corners-def annotate_image_with_charuco_data(image, port_number, charuco_corners, charuco_ids) -> bool:+def _board_text(+ cam_name: str,+ charuco_ids: List[int],+ charuco_corners: int,+ charuco_detect_bool: bool,+):+ ids_as_str = str(len(charuco_ids))+ corners_as_str = str(charuco_corners)+ text = (+ f"{cam_name}: {ids_as_str} of {corners_as_str} Charuco Corner Points Detected "+ f"| Full Board Detected: {charuco_detect_bool}"+ )+ return text+++def annotate_image_with_charuco_data(+ image, webcam_id: str, charuco_corners, charuco_ids+) -> bool:full_charuco_detected_on_this_frame = Falseif len(charuco_ids) == num_charuco_corners:full_charuco_detected_on_this_frame = True- image_w_markers = cv2.aruco.drawDetectedCornersCharuco(image,- np.array(charuco_corners),- np.array(charuco_ids),- (0, 255, 125, 255)) # yellow? I+ image_w_markers = cv2.aruco.drawDetectedCornersCharuco(+ image, np.array(charuco_corners), np.array(charuco_ids), (0, 255, 125, 255)+ ) # yellow? I# think cv2 uses BGR instead of RGB?- this_cam_name = "Camera " + str(port_number)+ this_cam_name = f"Camera {webcam_id}"- text_to_write_on_this_camera = ''- current_cam_corner_count_str = this_cam_name + ": " + str(- len(charuco_ids)) + " of " + str(- num_charuco_corners) + " ChAruco Corner Points detected | Full Board Detected: " + str(- full_charuco_detected_on_this_frame)+ text_to_write_on_this_camera = ""+ current_cam_corner_count_str = _board_text(+ this_cam_name,+ charuco_ids,+ num_charuco_corners,+ full_charuco_detected_on_this_frame,+ )+ # current_cam_corner_count_str = this_cam_name + ": " + str(+ # len(charuco_ids)) + " of " + str(+ # num_charuco_corners) + " ChAruco Corner Points detected | Full Board Detected: " + str(+ # full_charuco_detected_on_this_frame)# TODO - Determine 'shared views' (i.e. frames in which a full board is detected by 2# cameras)# TODO - self.determine_shared_charuco_board_views()@@ -36,9 +60,10 @@ def annotate_image_with_charuco_data(image, port_number, charuco_corners, chaructext_to_write_on_this_camera, # textposition, # position at which writing has to startcv2.FONT_HERSHEY_SIMPLEX, # font family- .5, # font size+ 0.5, # font size(30, 10, 0, 255), # font color- 2) # font stroke (draw a darker heavier font beneath a lighter/thinner copy for+ 2,+ ) # font stroke (draw a darker heavier font beneath a lighter/thinner copy for# readability)cv2.putText(@@ -48,12 +73,15 @@ def annotate_image_with_charuco_data(image, port_number, charuco_corners, charuccv2.FONT_HERSHEY_SIMPLEX,# font family (very limited selection, i think there's some interesting CV history# here...)- .5, # font size+ 0.5, # font size(209, 180, 0, 255), # font color- 1) # font stroke+ 1,+ ) # font strokeif full_charuco_detected_on_this_frame:- cv2.polylines(image_w_markers, np.int32([charuco_corners]), False, (0, 100, 255), 2)+ cv2.polylines(+ image_w_markers, np.int32([charuco_corners]), False, (0, 100, 255), 2+ )# for these_corners in charuco_points_from_previous_frames:# if len(these_corners)>0:# cv2.polylines(image_w_markers, np.int32([these_corners]), True, (0,100,255,