Free Motion Capture for Everyone πβ¨
TypeScript
`session_router` method works up to 'calibration'
Jon66f21c11842d
diff --git a/src/api/routes/session/session_router.py b/src/api/routes/session/session_router.pyindex e00a5ca5..cd25f554 100644--- a/src/api/routes/session/session_router.py+++ b/src/api/routes/session/session_router.py@@ -18,6 +18,7 @@ logger = logging.getLogger(__name__)session_router = APIRouter()+class TweakedPydanticBaseModel(BaseModel):class Config:arbitrary_types_allowed = True@@ -68,18 +69,17 @@ def calibrate_session(session_calibrate_model: SessionCalibrateModel = SessionCasession_id = get_most_recent_session_id()calibration_orchestrator = CalibrationPipelineOrchestrator(session_id)- # calibration_orchestrator.record_videos(show_visualizer_gui=True,- # save_video_in_frame_loop=False,- # show_camera_views_in_windows=False,- # )-- launch_camera_frame_loop(session_id=session_id,- webcam_configs_dict=session_calibrate_model.webcam_configs_dict,- opencv_camera_manager=session_calibrate_model.opencv_camera_manager,- show_camera_views_in_windows=True,- calibration_videos_bool=True,- detect_charuco_in_image=True,- )+ calibration_orchestrator.record_videos(show_visualizer_gui=False,+ save_video_in_frame_loop=False,+ show_camera_views_in_windows=True,+ )++ # launch_camera_frame_loop(session_id=session_id,+ # webcam_configs_dict=session_calibrate_model.webcam_configs_dict,+ # show_camera_views_in_windows=True,+ # calibration_videos_bool=True,+ # detect_charuco_in_image=True,+ # )calibration_orchestrator.run_anipose_camera_calibration(charuco_square_size=session_calibrate_model.charuco_square_size,pin_camera_0_to_origin=True)@@ -138,20 +138,21 @@ def visualize_session_offline(session_id_model: SessionIdModel = None):if __name__ == "__main__":# create_sessionsession_id_in = create_session_id('session_router_as_main')- session_id_model = SessionIdModel(session_id=session_id)+ session_id_model = SessionIdModel(session_id=session_id_in)# #calibrate_sessionsession_calibrate_model_in = SessionCalibrateModel(session_id=session_id_in,- charuco_square_size=39)+ charuco_square_size=39)calibrate_session(session_calibrate_model_in)- # record new session- record_session(session_id_model)-- # #process_+ # # record new session+ # record_session(session_id_model)+ #+ # # #process_# mediapipe_track_2D_skeletons_offline(session_id_model)+ # #+ # mediapipe_reconstruct_3D_skeletons_offline(session_id_model)#- mediapipe_reconstruct_3D_skeletons_offline(session_id_model)+ # # #visualize with PyQt/OpenGL#- # #visualize with PyQt/OpenGL# visualize_session_offline(session_id_model)diff --git a/src/cameras/capture/opencv_camera/camera_stream_thread_handler.py b/src/cameras/capture/opencv_camera/camera_stream_thread_handler.pyindex 886e5b26..217f12ce 100644--- a/src/cameras/capture/opencv_camera/camera_stream_thread_handler.py+++ b/src/cameras/capture/opencv_camera/camera_stream_thread_handler.py@@ -53,15 +53,6 @@ class VideoCaptureThread(threading.Thread):"""Is the thread capturing frames from the cameras (but not necessarily recording them, that's handled by `is_recording_frames`)"""return self._is_capturing_frames- @property- def is_recording_frames(self) -> bool:- """Is the thread *recording* the frames that are being capture from the camera (see also - `is_capturing_frames"""- return self._is_recording_frames-- @is_recording_frames.setter- def is_recording_frames(self, recording_frames_bool:bool):- self._is_recording_frames = recording_frames_bool-def stop(self):self._is_capturing_frames = False@@ -79,9 +70,7 @@ class VideoCaptureThread(threading.Thread):self._elapsed_during_frame_grab.append(time.perf_counter_ns() - start)self._timestamps_npy.append(self._frame.timestamp_in_seconds_from_record_start)self._num_frames_processed += 1- # logger.debug(f"Camera {self._webcam_id}: captured frame# {self._num_frames_processed}: Recording? {self.is_recording_frames}")- if self.is_recording_frames:- self._frame_list.append(self._frame)+ # logger.debug(f"Camera {self._webcam_id}: captured frame# {self._num_frames_processed}")except:logger.error("Frame loop thread exited due to error")traceback.print_exc()diff --git a/src/cameras/capture/opencv_camera/opencv_camera.py b/src/cameras/capture/opencv_camera/opencv_camera.pyindex 3c675017..388c9d7c 100644--- a/src/cameras/capture/opencv_camera/opencv_camera.py+++ b/src/cameras/capture/opencv_camera/opencv_camera.py@@ -127,8 +127,6 @@ class OpenCVCamera:logger.debug(f"Camera found at port number {self._config.webcam_id}")- fps_input_stream = int(self._opencv_video_capture_object.get(5))- logger.debug("FPS of webcam hardware/input stream: {}".format(fps_input_stream))if self.session_id is False:logger.info(@@ -209,8 +207,8 @@ class OpenCVCamera:if success:self._number_of_frames_recorded += 1- if self._camera_view_update_function is not None:- self._camera_view_update_function(self.webcam_id_as_str, cv2.cvtColor(image, cv2.COLOR_BGR2RGB))+ # if self._camera_view_update_function is not None:+ # self._camera_view_update_function(self.webcam_id_as_str, cv2.cvtColor(image, cv2.COLOR_BGR2RGB))return FramePayload(success=success,image=image,diff --git a/src/cameras/launch_camera_frame_loop.py b/src/cameras/launch_camera_frame_loop.pyindex a980a944..e7a95eae 100644--- a/src/cameras/launch_camera_frame_loop.py+++ b/src/cameras/launch_camera_frame_loop.py@@ -19,23 +19,21 @@ logger = logging.getLogger(__name__)def launch_camera_frame_loop(session_id: str,webcam_configs_dict: Dict[str, WebcamConfig] = None,- opencv_camera_manager: OpenCVCameraManager = None,- show_camera_views_in_windows: bool = False,+ show_camera_views_in_windows: bool = True,calibration_videos_bool: bool = False,detect_charuco_in_image: bool = True,camera_view_update_function=None,- update_gui_function = None,- exit_event_bool:bool = False,+ # update_gui_function=None,+ record_frames_bool: bool = True):-any_frames_recorded = Falseif detect_charuco_in_image:charuco_board_detector = CharucoBoardDetector()- if opencv_camera_manager is None:- opencv_camera_manager = OpenCVCameraManager(session_id=session_id,- expected_framerate=None)++ opencv_camera_manager = OpenCVCameraManager(session_id=session_id,+ expected_framerate=None)with opencv_camera_manager.start_capture_session_all_cams(webcam_configs_dict=webcam_configs_dict,camera_view_update_function=camera_view_update_function,@@ -44,8 +42,8 @@ def launch_camera_frame_loop(should_continue = Truewhile should_continue:- if update_gui_function is None:- update_gui_function()+ # if update_gui_function is None:+ # update_gui_function()for this_webcam_id, this_opencv_camera in connected_cameras_dict.items():this_frame_payload = this_opencv_camera.latest_frame@@ -64,15 +62,18 @@ def launch_camera_frame_loop(opencv_camera_manager.timestamp_manager)+ if record_frames_bool:+ any_frames_recorded = True+ this_opencv_camera.record_frames(True)+ else:+ this_opencv_camera.record_frames(False)+# exit loop when user presses ESC keyexit_key = cv2.waitKey(1)if exit_key == 27:logger.info("ESC has been pressed.")should_continue = False- if exit_event_bool is not None:- if exit_event_bool:- should_continue = Falseexcept:logger.error("Printing traceback")traceback.print_exc()diff --git a/src/cameras/multicam_manager/cv_camera_manager.py b/src/cameras/multicam_manager/cv_camera_manager.pyindex 09950ee8..05ca0dbf 100644--- a/src/cameras/multicam_manager/cv_camera_manager.py+++ b/src/cameras/multicam_manager/cv_camera_manager.py@@ -137,6 +137,7 @@ class OpenCVCameraManager:for cv_cam in open_cv_camera_objects:self._connected_cameras_dict[cv_cam.webcam_id_as_str] = cv_camself._start_frame_capture_on_cam_id(cv_cam)+yield self._connected_cameras_dictself._stop_frame_capture(open_cv_camera_objects)diff --git a/src/freemocap_qt_gui/freemocap_qt_gui.py b/src/freemocap_qt_gui/freemocap_qt_gui.pyindex 225c9ddd..b90abe5b 100644--- a/src/freemocap_qt_gui/freemocap_qt_gui.py+++ b/src/freemocap_qt_gui/freemocap_qt_gui.py@@ -23,6 +23,7 @@ from src.cameras.multicam_manager.cv_camera_manager import OpenCVCameraManagerfrom src.cameras.launch_camera_frame_loop import launch_camera_frame_loopfrom src.config.home_dir import create_session_idfrom src.config.webcam_config import WebcamConfig, webcam_config_to_qt_parameter_list+from src.pipelines.calibration_pipeline.calibration_pipeline_orchestrator import CalibrationPipelineOrchestratorlogger = logging.getLogger(__name__)@@ -81,7 +82,7 @@ class FreemocapQtGUI:self._setup_welcome_panel()self._main_window_widget.show()- def _setup_main_window(self, window_width: int = 300, window_height: int = 1):+ def _setup_main_window(self, window_width: int = 400, window_height: int = 1):"""This is the main main window for the GUI.Its structure is based loosely on the 'Dock Widgets' example from `python -m pyqtgraph.examples`@@ -121,7 +122,7 @@ class FreemocapQtGUI:self._welcome_panel_layout_widget.addWidget(self._start_button, row='next')self._shut_down_button = QtWidgets.QPushButton('Shut it down! π¦')- self._shut_down_button.hide()+ # self._shut_down_button.hide()self._shut_down_button.setEnabled(True)self._shut_down_button.clicked.connect(self.shut_it_down)@@ -129,7 +130,7 @@ class FreemocapQtGUI:def _create_setup_control_panel(self):- self._main_window_width += 100+ # self._main_window_width += 100self._main_window_height = 500self._main_window_widget.resize(self._main_window_width, self._main_window_height)@@ -140,7 +141,8 @@ class FreemocapQtGUI:'bottom',self._welcome_panel_dock)self._detect_available_cameras_text = 'Detect Available Cameras ππ₯'- self._detect_cameras_button = QtWidgets.QPushButton(self._detect_available_cameras_text + self._pointing_arrow_emoji)+ self._detect_cameras_button = QtWidgets.QPushButton(+ self._detect_available_cameras_text + self._pointing_arrow_emoji)self._detect_cameras_button.setEnabled(True)self._detect_cameras_button.clicked.connect(self._detect_available_cameras)self._setup_panel_layout_widget.addWidget(self._detect_cameras_button)@@ -156,7 +158,8 @@ class FreemocapQtGUI:self._connect_to_cameras_button.hide()self._setup_panel_layout_widget.addWidget(self._connect_to_cameras_button, row=0, col=1)- self._calibrate_cameras_button = QtWidgets.QPushButton('(wip) Record Camera Calibration Videos π₯ π')+ self._calibrate_cameras_button_text = 'Record Camera Calibration Videos π₯ π'+ self._calibrate_cameras_button = QtWidgets.QPushButton(self._calibrate_cameras_button_text)self._calibrate_cameras_button.setEnabled(True)self._calibrate_cameras_button.clicked.connect(self._record_calibration_videos)self._calibrate_cameras_button.hide()@@ -168,29 +171,24 @@ class FreemocapQtGUI:# self._use_previous_calibration_checkbox.hide()# self._setup_panel_layout_widget.addWidget(self._use_previous_calibration_checkbox, row=1, col=1)#- self._launch_camera_windows_button = QtWidgets.QPushButton('(broken)Record freemocap session π₯ π')- self._launch_camera_windows_button.setEnabled(True)- self._launch_camera_windows_button.clicked.connect(self._launch_camera_windows)- self._launch_camera_windows_button.hide()- self._setup_panel_layout_widget.addWidget(self._launch_camera_windows_button, row=2, col=1)+ # self._launch_camera_windows_button = QtWidgets.QPushButton('(broken)Record freemocap session π₯ π')+ # self._launch_camera_windows_button.setEnabled(True)+ # self._launch_camera_windows_button.clicked.connect(self._launch_camera_windows)+ # self._launch_camera_windows_button.hide()+ # self._setup_panel_layout_widget.addWidget(self._launch_camera_windows_button, row=2, col=1)def _start(self):logger.debug('start button pressed')- self._start_button.text = self._start_button_text+ self._start_button.setText(self._start_button_text)self._shut_down_button.show()self._lock_in_session_id(self.session_id_line_edit.text())# self._start_button.setText("Reset π«")- self._start_button.hide()+ # self._start_button.hide()+ self._start_button.setEnabled(False)self._create_setup_control_panel()- # def _check_if_have_calibration(self):- # if self._have_calibration_bool or self._use_previous_calibration_checkbox.isChecked():- # self._launch_camera_windows_button.show()- # else:- # self._launch_camera_windows_button.hide()-def _launch_camera_windows(self):logger.debug("`launch camera windows` button pressed")session_id_model = SessionIdModel(session_id=self.session_id)@@ -208,7 +206,7 @@ class FreemocapQtGUI:logger.debug(f"`get_or_create_cams()` returned:_available_cameras_dictionary {self._dictionary_of_available_webcam_configs}")- self._detect_cameras_button.setText('Re-Detect Available Cameras ππ₯' )+ self._detect_cameras_button.setText('Re-Detect Available Cameras ππ₯')self.hint_label.hide()if self._available_cameras_data_tree_widget is None:@@ -221,30 +219,36 @@ class FreemocapQtGUI:self._connect_to_cameras_button.setText(self._connect_to_cameras_button_text + self._pointing_arrow_emoji)self._connect_to_cameras_button.show()- # self._calibrate_cameras_button.show()# self._launch_camera_windows_button.show()- # self._use_previous_calibration_checkbox.show()-def _connect_to_cameras(self):- self._main_window_width = self._main_window_width *2+ logger.debug("`connect to cameras` button was pressed")+ self._main_window_width = self._main_window_width * 2# self._main_window_height- self._main_window_widget.resize(self._main_window_width, self._main_window_height)+ self._main_window_widget.resize(int(self._main_window_width), int(self._main_window_height))self._dictionary_of_camera_qt_image_items = self._create_camera_view_docks(self._dictionary_of_available_webcam_configs)self.pyqtgraph_app.processEvents()+ self._connect_to_cameras_button.setEnabled(False)+ self._connect_to_cameras_button.setText(self._connect_to_cameras_button_text)+ self._calibrate_cameras_button.setText(self._calibrate_cameras_button_text + self._pointing_arrow_emoji)+ self._calibrate_cameras_button.show()++ self._record_frames = Falselaunch_camera_frame_loop(session_id=self.session_id,webcam_configs_dict=self._dictionary_of_available_webcam_configs,opencv_camera_manager=self._opencv_camera_manager,camera_view_update_function=self.update_camera_view_image,- update_gui_function=self.pyqtgraph_app.processEvents)+ # update_gui_function=self.pyqtgraph_app.processEvents,+ record_frames_bool=self._record_frames)+ # self._use_previous_calibration_checkbox.show()def _create_camera_view_docks(self, dictionary_of_available_webcams) -> Dict:- pg.setConfigOptions(imageAxisOrder='row-major') #set this so camera images aren't rotated+ pg.setConfigOptions(imageAxisOrder='row-major') # set this so camera images aren't rotateddictionary_of_camera_qt_image_items = {}for this_webcam_id in dictionary_of_available_webcams.keys():dictionary_of_camera_qt_image_items[this_webcam_id] = self._setup_camera_view_dock(this_webcam_id)@@ -273,13 +277,23 @@ class FreemocapQtGUI:def _record_calibration_videos(self):logger.debug("`launch camera windows` button pressed")- # #calibrate_session- session_calibrate_model = SessionCalibrateModel(session_id=self._session_id,- webcam_configs_dict=self._dictionary_of_available_webcam_configs,- # opencv_camera_manager=self._opencv_camera_manager,- charuco_square_size=39)- calibrate_session(session_calibrate_model)- self._have_calibration_bool = True++ if not self._record_frames:+ self._record_frames = True+ self._calibrate_cameras_button.setText("Recording.... π΄")+ # #calibrate_session+ # session_calibrate_model = SessionCalibrateModel(session_id=self._session_id,+ # webcam_configs_dict=self._dictionary_of_available_webcam_configs,+ # # opencv_camera_manager=self._opencv_camera_manager,+ # charuco_square_size=39)+ # calibrate_session(session_calibrate_model)+ else:+ self._record_frames = False+ calibration_orchestrator = CalibrationPipelineOrchestrator(session_id=self.session_id)++ calibration_orchestrator.run_anipose_camera_calibration(+ charuco_square_size=39,+ pin_camera_0_to_origin=True)def _update_webcam_config_parameter_tree(self,dictionary_of_available_webcams: Dict[str, WebcamConfig]):diff --git a/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py b/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.pyindex daae9324..ebf3b9a2 100644--- a/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py+++ b/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py@@ -35,7 +35,7 @@ class CalibrationPipelineOrchestrator:self._calibration_start_time_unix_ns = time.time_ns()self._charuco_board_detector = CharucoBoardDetector()- self._visualizer_gui = QTVisualizerAndGui()+ self._visualizer_gui = Noneself._expected_framerate = expected_framerateself._open_cv_camera_manager = OpenCVCameraManager(session_id=self._session_id,expected_framerate=self._expected_framerate)@@ -50,7 +50,7 @@ class CalibrationPipelineOrchestrator:def record_videos(self,- show_visualizer_gui=True,+ show_visualizer_gui=False,show_camera_views_in_windows=True,save_video_in_frame_loop=False,@@ -63,6 +63,7 @@ class CalibrationPipelineOrchestrator:timestamp_manager = self._open_cv_camera_manager.timestamp_managertry:if show_visualizer_gui:+ self._visualizer_gui = QTVisualizerAndGui()self._visualizer_gui.setup_and_launch(self._open_cv_camera_manager.available_webcam_ids)should_continue = True