Free Motion Capture for Everyone πβ¨
TypeScript
videos save and anipose calibration procedure begins when push 'stop recording'
Jond81e70a214da
diff --git a/src/cameras/persistence/video_writer/video_recorder.py b/src/cameras/persistence/video_writer/video_recorder.pyindex 44c19642..9e3f1a94 100644--- a/src/cameras/persistence/video_writer/video_recorder.py+++ b/src/cameras/persistence/video_writer/video_recorder.py@@ -40,12 +40,12 @@ class VideoRecorder:self._session_id = session_idsession_path = Path(get_session_folder_path(self._session_id))- if mediapipe_annotated_video_bool:- self._video_folder_path = Path(get_mediapipe_annotated_videos_folder_path(self._session_id))- elif calibration_video_bool:- self._video_folder_path = Path(get_calibration_videos_folder_path(self._session_id))- else:- self._video_folder_path = Path(get_synchronized_videos_folder_path(self._session_id))+ # if mediapipe_annotated_video_bool:+ # self._video_folder_path = Path(get_mediapipe_annotated_videos_folder_path(self._session_id))+ # elif calibration_video_bool:+ # self._video_folder_path = Path(get_calibration_videos_folder_path(self._session_id))+ # else:+ # self._video_folder_path = Path(get_synchronized_videos_folder_path(self._session_id))@property@@ -83,8 +83,12 @@ class VideoRecorder:self._frame_payload_list.append(frame_payload)def save_list_of_frames_to_video_file(self,- list_of_frames:List[FramePayload],- frames_per_second:float=None):+ list_of_frames:List[FramePayload]=None,+ frames_per_second:float=None,+ calibration_videos:bool=False):+ if list_of_frames is None:+ list_of_frames = self._frame_payload_list+if len(list_of_frames) == 0:logging.error(f"No frames to save for camera: {self._video_name}")raise Exception@@ -93,7 +97,7 @@ class VideoRecorder:self._timestamps_npy = self._gather_timestamps(list_of_frames)frames_per_second = np.nanmedian((np.diff(self._timestamps_npy) ** -1))- self._initialize_video_writer(frames_per_second=frames_per_second)+ self._initialize_video_writer(frames_per_second=frames_per_second, calibration_videos=calibration_videos)self._write_frame_list_to_video_file(list_of_frames)self._save_timestamps(self._timestamps_npy)@@ -107,9 +111,15 @@ class VideoRecorder:self._initialize_video_writer(frames_per_second=frames_per_second)self._write_image_list_to_video_file(image_list)- def _initialize_video_writer(self, frames_per_second: Union[int, float] = None):+ def _initialize_video_writer(self, frames_per_second: Union[int, float] = None, calibration_videos:bool=False):video_file_name = self._video_name + '.mp4'++ if calibration_videos:+ self._video_folder_path = Path(get_calibration_videos_folder_path(self._session_id))+ else:+ self._video_folder_path = Path(get_synchronized_videos_folder_path(self._session_id))+self._path_to_save_video_file = self._video_folder_path / video_file_nameframes_per_second = frames_per_seconddiff --git a/src/freemocap_qt_gui/conference/workers/cam_charuco_frame_worker.py b/src/freemocap_qt_gui/conference/workers/cam_charuco_frame_worker.pyindex 33dd198b..63fbe9b9 100644--- a/src/freemocap_qt_gui/conference/workers/cam_charuco_frame_worker.py+++ b/src/freemocap_qt_gui/conference/workers/cam_charuco_frame_worker.py@@ -4,6 +4,7 @@ from PyQt6.QtGui import QImagefrom src.cameras.capture.opencv_camera.opencv_camera import OpenCVCamerafrom src.config.webcam_config import WebcamConfig+from src.freemocap_qt_gui.refactored_gui.state.app_state import APP_STATEfrom src.pipelines.calibration_pipeline.charuco_board_detection.charuco_board_detector import \CharucoBoardDetector@@ -11,26 +12,45 @@ from src.pipelines.calibration_pipeline.charuco_board_detection.charuco_board_declass CamCharucoFrameWorker(QThread):ImageUpdate = pyqtSignal(QImage)- def __init__(self, cam_id=None):+ def __init__(self, cam_id=None, should_save_frames:bool=False, calibration_videos=False):super().__init__()self._board_thingy = CharucoBoardDetector()self._cam_id = cam_id+ self._should_save_frames = should_save_frames+ self._should_continue = True++ @property+ def should_save_frames(self):+ return self._should_save_frames++ @should_save_frames.setter+ def should_save_frames(self, value):+ self._should_save_frames = value+def run(self):cam = OpenCVCamera(WebcamConfig(webcam_id=self._cam_id- )+ ),+ session_id=APP_STATE.session_id,)cam.connect()cam.start_frame_capture_thread()self._cam = cam+ any_frames_recorded = Falsetry:while cam.is_capturing_frames:if not cam.new_frame_ready:continuepayload = cam.latest_frame++ if self._should_save_frames:+ any_frames_recorded = True+ print("saving frame :D")+ cam.video_recorder.append_frame_payload_to_list(payload)+charuco_payload = self._board_thingy.detect_charuco_board(payload)image_to_display = charuco_payload.annotated_imageimage_to_display = cv2.flip(image_to_display, 1)@@ -44,8 +64,12 @@ class CamCharucoFrameWorker(QThread):converted_frame = converted_frame.scaled(640, 480, Qt.AspectRatioMode.KeepAspectRatio)self.ImageUpdate.emit(converted_frame)finally:- print("Closing the camera")+ print(f"Closing the camera {self._cam.webcam_id_as_str}, and saving video to disk")self._cam.close()+ if any_frames_recorded:+ print(f"saving video for camera {self._cam.webcam_id_as_str}")+ self._cam.video_recorder.save_list_of_frames_to_video_file(calibration_videos=True)+ print(f"Saved video to: {str(self._cam.video_recorder.path_to_save_video_file)}")def quit(self):self._cam.close()diff --git a/src/freemocap_qt_gui/conference/workers/cam_frame_worker.py b/src/freemocap_qt_gui/conference/workers/cam_frame_worker.pyindex 9bd84e38..f1b8e5bb 100644--- a/src/freemocap_qt_gui/conference/workers/cam_frame_worker.py+++ b/src/freemocap_qt_gui/conference/workers/cam_frame_worker.py@@ -27,6 +27,7 @@ class CamFrameWorker(QThread):if not cam.new_frame_ready:continuepayload = cam.latest_frame+image = cv2.flip(payload.image, 1)image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)converted_frame = QImage(diff --git a/src/freemocap_qt_gui/conference/workflows/show_cams_charuco.py b/src/freemocap_qt_gui/conference/workflows/show_cams_charuco.pyindex b5242b47..53014bf2 100644--- a/src/freemocap_qt_gui/conference/workflows/show_cams_charuco.py+++ b/src/freemocap_qt_gui/conference/workflows/show_cams_charuco.py@@ -1,7 +1,8 @@-from PyQt6.QtWidgets import QHBoxLayout, QLabel, QVBoxLayout, QWidget+from PyQt6.QtWidgets import QHBoxLayout, QLabel, QVBoxLayout, QWidget, QPushButtonfrom src.freemocap_qt_gui.conference.workflows.single_camera import SingleCamerafrom src.freemocap_qt_gui.refactored_gui.state.app_state import APP_STATE+from src.pipelines.calibration_pipeline.calibration_pipeline_orchestrator import CalibrationPipelineOrchestratorclass ShowCamsCharuco(QWidget):@@ -18,15 +19,48 @@ class ShowCamsCharuco(QWidget):title_layout.addWidget(title)video_stream_layout = QHBoxLayout()- cam_widgets = []+ self._cam_widgets = []for cam_id in self._selected_cams:single_cam = SingleCamera(cam_id)single_cam.capture()video_stream_layout.addWidget(single_cam)- cam_widgets.append(single_cam)+ self._cam_widgets.append(single_cam)container.addLayout(title_layout)container.addLayout(video_stream_layout)+ #start/stop recording button layout+ record_button_layout = QHBoxLayout()+ self._start_recording_button = QPushButton('Begin Recording')+ self._stop_recording_button = QPushButton('Stop Recording')++ self._start_recording_button.clicked.connect(self._start_recording_frames)+ self._stop_recording_button.clicked.connect(self._stop_recording_frames)++ record_button_layout.addWidget(self._start_recording_button)+ record_button_layout.addWidget(self._stop_recording_button)+ container.addLayout(record_button_layout)+self.setLayout(container)++ def _start_recording_frames(self):+ for cam in self._cam_widgets:+ cam.should_record_frames = True++ def _stop_recording_frames(self):+ for cam in self._cam_widgets:+ cam.quit()++ self._run_anipose_calibration()++ def _run_anipose_calibration(self):+ print('Beginning Anipose calibration')+ calibration_orchestrator = CalibrationPipelineOrchestrator(APP_STATE.session_id)+ try:+ calibration_orchestrator.run_anipose_camera_calibration(+ charuco_square_size=39,+ pin_camera_0_to_origin=True)+ except:+ print('something failed in the anipose calibration')+ raise Exception\ No newline at end of filediff --git a/src/freemocap_qt_gui/conference/workflows/single_camera.py b/src/freemocap_qt_gui/conference/workflows/single_camera.pyindex 2285606b..8d4a3215 100644--- a/src/freemocap_qt_gui/conference/workflows/single_camera.py+++ b/src/freemocap_qt_gui/conference/workflows/single_camera.py@@ -37,10 +37,22 @@ class SingleCamera(QWidget):self.setLayout(layout)+ @property+ def should_record_frames(self):+ return self._worker.should_save_frames++ @should_record_frames.setter+ def should_record_frames(self, value):+ self._worker.should_save_frames = value+def capture(self):self._create_preview_worker()self.started.emit()+ def quit(self):+ self._worker.quit()++def _init_frame_worker(self):worker = construct_worker(WorkerType.CHARUCO)(self._cam_id)worker.ImageUpdate.connect(self._handle_image_update)