Free Motion Capture for Everyone πβ¨
TypeScript
add private state
Endurance Idehene8c15890a6af
diff --git a/jon_scratch/opencv_camera.py b/jon_scratch/opencv_camera.pyindex 7636681f..30656f0a 100644--- a/jon_scratch/opencv_camera.py+++ b/jon_scratch/opencv_camera.py@@ -41,6 +41,13 @@ class OpenCVCamera(TweakedModel):_is_capturing_frames: bool = PrivateAttr(False)_running_thread = PrivateAttr(None)_last_100_frames: deque = PrivateAttr(deque(maxlen=100))+ _fps: float = PrivateAttr(0)+ _num_frames_processed: int = PrivateAttr(0)+ _frame: tuple = PrivateAttr(None)++ @property+ def current_fps(self):+ return self._fpsdef connect(self):if platform.system() == "Windows":@@ -88,15 +95,20 @@ class OpenCVCamera(TweakedModel):print("Thread should be stopped")def latest_frame(self):- if self._last_100_frames:- return self._last_100_frames.pop()- return False, None, None+ if not self._frame:+ return False, None, None+ return self._framedef _start_frame_loop(self):self._is_capturing_frames = True+ start = time.time()while self._is_capturing_frames:success, image, timestamp = self.get_next_frame()+ self._frame = (success, image, timestamp)self._last_100_frames.append((success, image, timestamp))+ self._num_frames_processed += 1+ elapsed = time.time() - start+ self._fps = self._num_frames_processed / elapseddef get_next_frame(self):timestamp_ns_pre_grab = time.time_ns()diff --git a/src/core_processor/board_detection/detect.py b/src/core_processor/board_detection/detect.pyindex dd40f3e8..1d4d74f1 100644--- a/src/core_processor/board_detection/detect.py+++ b/src/core_processor/board_detection/detect.py@@ -26,14 +26,15 @@ class BoardDetection:for cv_cam in cv_cams:success, frame, timestamp = cv_cam.latest_frame()if not success:+ print("fail")continue-if frame is None:+ print("no frame found")continueport_number = str(cv_cam.port_number)- print(- f"got image of shape {frame.shape} from camera at port {port_number}"- )+ # print(+ # f"got image of shape {frame.shape} from camera at port {port_number}"+ # )(charuco_corners,charuco_ids,@@ -48,12 +49,23 @@ class BoardDetection:cv2.polylines(frame, np.int32([charuco_corners]), True, (0, 100, 255), 2)-+ self.apply_fps(frame, cv_cam.current_fps)cv2.imshow(port_number, frame)exit_key = cv2.waitKey(1)if exit_key == 27:break+ def apply_fps(self, image, fps_number):+ cv2.putText(+ image,+ f"FPS: {str(fps_number)}",+ (10, 15),+ cv2.FONT_HERSHEY_SIMPLEX,+ 0.5,+ (209, 180, 0, 255),+ 1,+ )+if __name__ == "__main__":## Jon, Run me to easily start a charuco board detect run