Free Motion Capture for Everyone πβ¨
TypeScript
not a bad proof-of-concept...
Jon09632ff046cd
diff --git a/requirements.txt b/requirements.txtindex 71a36ca4..db1cec5f 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,15 +1,3 @@-#aniposelib==0.4.3-#h5py>=3.1.0-#imutils~=0.5.4-#matplotlib~=3.5.1-## mediapipe==0.8.8-#opencv-contrib-python==4.5.5.62-#pandas~=1.2.5-#rich~=10.4.0-#tqdm~=4.61.1-#ruamel.yaml>=0.15.0-#typed-ast<1.5,>=1.4.0-#moviepy ~=1.0.3ipythonnumpy>=1.19pydantic==1.9.0@@ -24,15 +12,13 @@ sqlalchemy==1.4.31singleton-decorator==1.0.0orjson==3.6.7aiomultiprocess==0.9.0-# faster-fifo==1.3.0-#viztracer==0.14.5pre-commit==2.17.0pandas==1.4.2imageioimageio-ffmpeg# Requirements for core-processorpyqtgraph==0.12.4-pyqt5==5.15.6+pyqt5~=5.12.1pyopengl==3.1.6mediapipe~=0.8.9.1setuptools~=58.0.4diff --git a/src/api/routes/session/session_router.py b/src/api/routes/session/session_router.pyindex 677967df..0ede0423 100644--- a/src/api/routes/session/session_router.py+++ b/src/api/routes/session/session_router.py@@ -6,7 +6,8 @@ from fastapi import APIRouterfrom pydantic import BaseModelfrom jon_scratch.pupil_calibration_pipeline.qt_gl_laser_skeleton_visualizer import QtGlLaserSkeletonVisualizer-from src.config.home_dir import create_session_id, get_session_folder_path, get_most_recent_session_id+from src.config.home_dir import create_session_id, get_session_folder_path, get_most_recent_session_id, \+ create_session_folderfrom src.pipelines.calibration_pipeline.calibration_pipeline_orchestrator import CalibrationPipelineOrchestratorfrom src.pipelines.session_pipeline.session_pipeline_orchestrator import SessionPipelineOrchestrator, \load_mediapipe3d_skeleton_data, load_mediapipe2d_data@@ -54,12 +55,12 @@ async def create_session(session_create_model: SessionCreateModel = SessionCreatdef calibrate_session(session_calibrate_model: SessionCalibrateModel = SessionCalibrateModel()):"""calibate capture volume - record synchronized videos (from all available camras wtih default parameters for now) and process with Anipose to produce a camera calibration (saved as a `.toml` file in the session folder"""- if session_calibrate_model.session_id is None or session_id_model.session_id == "string":- this_session_id = get_most_recent_session_id()- else:- this_session_id = session_calibrate_model.session_id+ session_id = session_calibrate_model.session_id+ if session_id is None or session_id == "string":+ session_id = get_most_recent_session_id()+- calibration_orchestrator = CalibrationPipelineOrchestrator(this_session_id)+ calibration_orchestrator = CalibrationPipelineOrchestrator(session_id)calibration_orchestrator.record_videos(show_visualizer_gui=False,save_video_in_frame_loop=False,show_camera_views_in_windows=True,diff --git a/src/cameras/capture/dataclasses/frame_payload.py b/src/cameras/capture/dataclasses/frame_payload.pyindex e060f480..96732e2b 100644--- a/src/cameras/capture/dataclasses/frame_payload.py+++ b/src/cameras/capture/dataclasses/frame_payload.py@@ -6,7 +6,7 @@ import numpy as npclass FramePayload(NamedTuple):success: bool = Falseimage: np.ndarray = None- timestamp: Union[int, float] = None+ timestamp_in_seconds_from_record_start: float = Noneframe_number: int = Nonewebcam_id: str = Nonediff --git a/src/cameras/capture/opencv_camera/camera_stream_thread_handler.py b/src/cameras/capture/opencv_camera/camera_stream_thread_handler.pyindex 9b68b896..cb99249d 100644--- a/src/cameras/capture/opencv_camera/camera_stream_thread_handler.py+++ b/src/cameras/capture/opencv_camera/camera_stream_thread_handler.py@@ -74,7 +74,7 @@ class VideoCaptureThread(threading.Thread):start = time.perf_counter_ns()self._frame = self._get_next_frame()self._elapsed_during_frame_grab.append(time.perf_counter_ns() - start)- self._timestamps_npy.append(self._frame.timestamp)+ self._timestamps_npy.append(self._frame.timestamp_in_seconds_from_record_start)self._num_frames_processed += 1if self.is_recording_frames:self._frame_list.append(self._frame)diff --git a/src/cameras/capture/opencv_camera/opencv_camera.py b/src/cameras/capture/opencv_camera/opencv_camera.pyindex b2c76913..3e9c33d3 100644--- a/src/cameras/capture/opencv_camera/opencv_camera.py+++ b/src/cameras/capture/opencv_camera/opencv_camera.py@@ -3,7 +3,7 @@ import loggingimport platformimport timeimport traceback-from typing import List+from typing import List, Unionimport cv2@@ -12,6 +12,7 @@ from src.cameras.persistence.video_writer.video_recorder import VideoRecorderfrom src.cameras.viewer.cv_cam_viewer import CvCamViewerfrom src.config.webcam_config import WebcamConfigfrom src.cameras.capture.opencv_camera.camera_stream_thread_handler import VideoCaptureThread+from src.core_processor.timestamp_manager.timestamp_manager import TimestampLoggerlogger = logging.getLogger(__name__)@@ -21,7 +22,17 @@ class OpenCVCamera:Performant implementation of video capture against webcams"""- def __init__(self, config: WebcamConfig, session_id: str = None, calibration_video_bool: bool = False):+ def __init__(self,+ config: WebcamConfig,+ session_id: str = None,+ timestamp_logger: TimestampLogger = None,+ calibration_video_bool: bool = False):++ if timestamp_logger is None:+ self._timestamp_logger = TimestampLogger()+ else:+ self._timestamp_logger = timestamp_logger+self._config = configself._name = f"Camera_{self._config.webcam_id}"self._opencv_video_capture_object: cv2.VideoCapture = None@@ -70,10 +81,6 @@ class OpenCVCamera:self._new_frame_ready = Falsereturn self._running_thread.latest_frame- @property- def frame_list(self) -> List:- return self._running_thread.frame_list-@propertydef latest_frame_number(self):return self._number_of_frames_recorded@@ -92,10 +99,9 @@ class OpenCVCamera:except Exception as e:raise e- def record_frames(self, save_frames_bool:bool):+ def record_frames(self, save_frames_bool: bool):self._running_thread.is_recording_frames = save_frames_bool-def connect(self):if platform.system() == "Windows":cap_backend = cv2.CAP_DSHOW@@ -178,12 +184,16 @@ class OpenCVCamera:if not self._opencv_video_capture_object.grab():return FramePayload(False, None, None)- timestamp_ns_pre = time.perf_counter_ns()+ # timestamp_ns_pre = time.perf_counter_ns()+ timestamp_ns_pre = time.time_ns()success, image = self._opencv_video_capture_object.retrieve()- timestamp_ns_post = time.perf_counter_ns()+ timestamp_ns_post = time.time_ns()+ # timestamp_ns_post = time.perf_counter_ns()- timestamp_ns = (timestamp_ns_pre + timestamp_ns_post) / 2+ it_took_this_many_seconds_to_grab_the_frame = (timestamp_ns_post-timestamp_ns_pre)/1e9+ self._timestamp_logger.log_new_timestamp_perf_counter_ns(time.perf_counter_ns())+ latest_timestamp_in_seconds_from_record_start = self._timestamp_logger.latest_timestamp_in_seconds_from_record_startself._new_frame_ready = successif success:@@ -191,7 +201,7 @@ class OpenCVCamera:return FramePayload(success=success,image=image,- timestamp=timestamp_ns,+ timestamp_in_seconds_from_record_start=latest_timestamp_in_seconds_from_record_start,frame_number=self.latest_frame_number,webcam_id=self.webcam_id_as_str)diff --git a/src/cameras/multicam_manager/cv_camera_manager.py b/src/cameras/multicam_manager/cv_camera_manager.pyindex a9cd6703..db46e6ac 100644--- a/src/cameras/multicam_manager/cv_camera_manager.py+++ b/src/cameras/multicam_manager/cv_camera_manager.py@@ -12,7 +12,7 @@ from src.cameras.capture.opencv_camera.opencv_camera import OpenCVCamerafrom src.cameras.detection.cam_singleton import get_or_create_camsfrom src.cameras.persistence.video_writer.video_recorder import VideoRecorderfrom src.config.webcam_config import WebcamConfig-from src.core_processor.timestamp_manager.timestamp_manager import TimestampManager+from src.core_processor.timestamp_manager.timestamp_manager import TimestampManager, TimestampLoggerfrom src.pipelines.session_pipeline.data_classes.multi_frame_payload import MultiFramePayloadlogger = logging.getLogger(__name__)@@ -37,6 +37,7 @@ class OpenCVCameraManager:self._session_start_time_unix_ns = Noneself._timestamp_manager: Union[TimestampManager, None] = Noneself._connected_cameras_dict = {}+ self._available_cameras_dict = {}self._expected_framerate = expected_framerate@property@@ -76,7 +77,7 @@ class OpenCVCameraManager:multi_frame_number=self._timestamp_manager.multi_frame_timestamp_logger.number_of_frames,intra_frame_interval=self._timestamp_manager.latest_multi_frame_interval,each_frame_timestamp=self._timestamp_manager.latest_multi_frame_timestamp_list,- multi_frame_timestamp=self._timestamp_manager.multi_frame_timestamp_logger.latest_timestamp,+ multi_frame_timestamp=self._timestamp_manager.multi_frame_timestamp_logger.latest_timestamp_in_seconds_from_record_start,)def new_multi_frame_ready(self):@@ -87,6 +88,14 @@ class OpenCVCameraManager:return Falsereturn True+ def get_available_cameras(self) -> Dict:+ for this_raw_camera in self._detected_cams_data.cameras_found_list:+ this_webcam_config = WebcamConfig()+ this_webcam_config.webcam_id = this_raw_camera.webcam_id+ self._available_cameras_dict[this_webcam_config.webcam_id] = this_webcam_config++ return self._available_cameras_dict+@contextmanagerdef start_capture_session_single_cam(self, webcam_id: str@@ -112,13 +121,16 @@ class OpenCVCameraManager:self,calibration_videos=False,) -> ContextManager[Dict[str, OpenCVCamera]]:- open_cv_camera_objects = self._create_opencv_cameras(calibration_videos=calibration_videos)++ self._initialize_timestamp_logger()+ open_cv_camera_objects = self._create_opencv_cameras(+ timestamp_manager=self._timestamp_manager,+ calibration_videos=calibration_videos, )try: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)- self._initialize_timestamp_logger()yield self._connected_cameras_dictself._stop_frame_capture(open_cv_camera_objects)@@ -126,16 +138,27 @@ class OpenCVCameraManager:logger.error("Printing traceback from starting capture session by cam")traceback.print_exc()- def _create_opencv_cameras(self, calibration_videos: bool = False):+ def _create_opencv_cameras(self,+ timestamp_manager:TimestampManager,+ calibration_videos: bool = False,+ ):++raw_camera_objects = self._detected_cams_data.cameras_found_listopen_cv_cameras: List[OpenCVCamera] = []for this_raw_cam in raw_camera_objects:- opencv_cam_obj = self._create_single_opencv_cam(this_raw_cam.webcam_id,+ this_cam_timestamp_logger = timestamp_manager.timestamp_logger_for_webcam_id(webcam_id=this_raw_cam.webcam_id)+ opencv_cam_obj = self._create_single_opencv_cam(webcam_id=this_raw_cam.webcam_id,+ timestamp_logger=this_cam_timestamp_logger,calibration_video_bool=calibration_videos)open_cv_cameras.append(opencv_cam_obj)return open_cv_cameras- def _create_single_opencv_cam(self, webcam_id: str, calibration_video_bool: bool = False):+ def _create_single_opencv_cam(self,+ webcam_id: str,+ timestamp_logger:TimestampLogger,+ calibration_video_bool: bool = False,+ ):webcam_config_model = self._config_service.webcam_config_by_id(webcam_id, self._session_id)single_camera_config = WebcamConfig(webcam_id=webcam_config_model.webcam_id,exposure=webcam_config_model.exposure,@@ -143,6 +166,7 @@ class OpenCVCameraManager:resolution_height=webcam_config_model.resolution_height, )return OpenCVCamera(config=single_camera_config,session_id=self._session_id,+ timestamp_logger=timestamp_logger,calibration_video_bool=calibration_video_bool)def _initialize_timestamp_logger(self):diff --git a/src/cameras/persistence/video_writer/video_recorder.py b/src/cameras/persistence/video_writer/video_recorder.pyindex 798dc371..44c19642 100644--- a/src/cameras/persistence/video_writer/video_recorder.py+++ b/src/cameras/persistence/video_writer/video_recorder.py@@ -64,6 +64,10 @@ class VideoRecorder:def frame_count(self):return len(self._frame_payload_list)+ @property+ def frame_list(self):+ return self._frame_payload_list+def save_frame_payload_to_video_file(self, frame_payload: FramePayload):@@ -78,21 +82,24 @@ class VideoRecorder:def append_frame_payload_to_list(self, frame_payload: FramePayload):self._frame_payload_list.append(frame_payload)- def save_list_of_frames_to_list_to_video_file(self, list_of_frames:List[FramePayload]):+ def save_list_of_frames_to_video_file(self,+ list_of_frames:List[FramePayload],+ frames_per_second:float=None):if len(list_of_frames) == 0:logging.error(f"No frames to save for camera: {self._video_name}")- return+ raise Exception- self._timestamps_npy = self._gather_timestamps(list_of_frames)+ if frames_per_second is None:+ self._timestamps_npy = self._gather_timestamps(list_of_frames)+ frames_per_second = np.nanmedian((np.diff(self._timestamps_npy) ** -1))- frames_per_second = float(np.nanmedian((np.diff(self._timestamps_npy) ** -1) / 1e9))self._initialize_video_writer(frames_per_second=frames_per_second)self._write_frame_list_to_video_file(list_of_frames)self._save_timestamps(self._timestamps_npy)def save_image_list_to_disk(self,image_list: List[np.ndarray],- frames_per_second: Union[int, float] = None):+ frames_per_second:float):if len(image_list) == 0:logging.error(f"No frames to save for : {self._video_name}")return@@ -143,7 +150,7 @@ class VideoRecorder:timestamps_npy = np.empty(0)try:for frame in list_of_frames:- timestamps_npy = np.append(timestamps_npy, frame.timestamp)+ timestamps_npy = np.append(timestamps_npy, frame.timestamp_in_seconds_from_record_start)except:logger.error("Error gathering timestamps")diff --git a/src/config/webcam_config.py b/src/config/webcam_config.pyindex 1ec9fd31..0a5cde9c 100644--- a/src/config/webcam_config.py+++ b/src/config/webcam_config.py@@ -1,4 +1,4 @@-+from typing import Listfrom pydantic import BaseModel@@ -14,3 +14,24 @@ class WebcamConfig(BaseModel):# fourcc: str = "MP4V"fourcc: str = "MJPG"base_save_video_dir = os_independent_home_dir()++def webcam_config_to_qt_parameter_list(webcam_config:WebcamConfig = WebcamConfig())->List:+ """+ take in a webcam_config and return a parameter_tree_group that you can feed into a pyqtgraph Parameter tree like this:++ ```python+ parameter_tree = ParameterTree()+ parameters_group = Parameter.create(name='Available Webcams', type='group',+ children=webcam_config_to_qt_parameter_group(WebcamConfig())+ parameter_tree.setParameters(parameters_group)+ ```+ """+ this_webcam_id = webcam_config.webcam_id+ parameter_list = [+ {'name': 'use this cameraβ', 'type': 'bool', 'value': True},+ {'name': 'exposure', 'type': 'int', 'value': webcam_config.exposure},+ {'name': 'resolution_width', 'type': 'int', 'value': webcam_config.resolution_width},+ {'name': 'resolution_height', 'type': 'int', 'value': webcam_config.resolution_height},+ ]++ return parameter_list\ No newline at end of filediff --git a/src/core_processor/timestamp_manager/timestamp_manager.py b/src/core_processor/timestamp_manager/timestamp_manager.pyindex b3353319..2c9bd7b6 100644--- a/src/core_processor/timestamp_manager/timestamp_manager.py+++ b/src/core_processor/timestamp_manager/timestamp_manager.py@@ -1,4 +1,5 @@import logging+import timefrom pathlib import Pathfrom typing import Dict, List, Union@@ -17,8 +18,11 @@ class TimestampLogger:_num_frames_processed: int_start_time: float- def __init__(self, _session_start_time_perf_counter_ns: int):- self._session_start_time_perf_counter_ns = _session_start_time_perf_counter_ns+ def __init__(self, session_start_time_perf_counter_ns: int=None):+ if session_start_time_perf_counter_ns is None:+ self._session_start_time_perf_counter_ns = time.perf_counter_ns()+ else:+ self._session_start_time_perf_counter_ns = session_start_time_perf_counter_nsself._num_frames_processed = 0self._timestamps_ns = np.empty(0)@@ -36,7 +40,7 @@ class TimestampLogger:return self._num_frames_processed@property- def timestamps_unix_ns(self):+ def timestamps_from_record_start_ns(self):"""return timestamps in nanoseconds in Unix epoch format (which is both the most useful, ugliest, AND funniest time format around. You can use `self.timestamps_in_seconds_from_zero()` for a more intuitive time format"""return self._timestamps_ns - self._session_start_time_perf_counter_ns@@ -50,13 +54,13 @@ class TimestampLogger:return (self._timestamps_ns - self._session_start_time_perf_counter_ns) / 1e9@property- def latest_timestamp(self):+ def latest_timestamp_in_seconds_from_record_start(self):"""returns timestamps in seconds from session start"""if self.timestamps.shape[0] > 0:return self.timestamps[-1]return None- def log_new_timestamp_ns(self, timestamp):+ def log_new_timestamp_perf_counter_ns(self, timestamp:int):self._timestamps_ns = np.append(self._timestamps_ns, timestamp)self._num_frames_processed += 1@@ -65,22 +69,34 @@ class TimestampManager:def __init__(self,session_id:str,webcam_ids: List[str],- session_start_time_unix_ns: int,- _session_start_time_perf_counter_ns:int):+ session_start_time_unix_ns: int=None,+ _session_start_time_perf_counter_ns:int=None):self._session_id = session_id- self._session_start_time_unix_ns = session_start_time_unix_ns #time.time_ns(), UNIX epoch time, nanoseconds- self._session_start_time_perf_counter_ns = _session_start_time_perf_counter_ns #time.perf_counter_ns, arbitrary timebase, nanoseconds - corresponds to self.session_start_time_ns++ if session_start_time_unix_ns is None:+ self._session_start_time_unix_ns = time.time_ns() # UNIX epoch time, nanoseconds+ else:+ self._session_start_time_unix_ns = session_start_time_unix_ns++ if _session_start_time_perf_counter_ns is None:+ self._session_start_time_perf_counter_ns = time.perf_counter_ns # arbitrary timebase, nanoseconds - corresponds to self._session_start_time_unix_ns+ else:+ self._session_start_time_perf_counter_ns = _session_start_time_perf_counter_nsself._webcam_ids = webcam_idsself._webcam_timestamp_loggers: Dict[str, TimestampLogger] = self._initialize_webcam_timestamp_loggers(webcam_ids)- self._main_loop_timestamp_logger = TimestampLogger(self._session_start_time_perf_counter_ns)- self._multi_frame_timestamp_logger = TimestampLogger(self._session_start_time_perf_counter_ns)+ self._main_loop_timestamp_logger = TimestampLogger(session_start_time_perf_counter_ns=self._session_start_time_perf_counter_ns)+ self._multi_frame_timestamp_logger = TimestampLogger(session_start_time_perf_counter_ns=self._session_start_time_perf_counter_ns)self._multi_frame_timestamps_list = []self._multi_frame_interval_list = []@propertydef webcam_timestamp_loggers(self):return self._webcam_timestamp_loggers++ def timestamp_logger_for_webcam_id(self, webcam_id:str)->TimestampLogger:+ return self._webcam_timestamp_loggers[webcam_id]+@propertydef number_of_cameras(self):return len(self._webcam_timestamp_loggers)@@ -108,7 +124,7 @@ class TimestampManager:def _initialize_webcam_timestamp_loggers(self, webcam_ids: List[str]):dictionary_of_timestamp_logger_objects = {}for webcam_id in webcam_ids:- dictionary_of_timestamp_logger_objects[webcam_id] = TimestampLogger(self._session_start_time_unix_ns)+ dictionary_of_timestamp_logger_objects[webcam_id] = TimestampLogger(session_start_time_perf_counter_ns=self._session_start_time_perf_counter_ns)return dictionary_of_timestamp_logger_objectsdef get_timestamps_from_camera_in_seconds_from_session_start(self, webcam_id):@@ -124,14 +140,14 @@ class TimestampManager:return self._webcam_timestamp_loggers[webcam_id].median_frames_per_seconddef log_new_timestamp_for_main_loop_ns(self, timestamp):- self._main_loop_timestamp_logger.log_new_timestamp_ns(timestamp)+ self._main_loop_timestamp_logger.log_new_timestamp_perf_counter_ns(timestamp)def log_new_multi_frame_timestamp_ns(self, timestamp):- self._multi_frame_timestamp_logger.log_new_timestamp_ns(timestamp)+ self._multi_frame_timestamp_logger.log_new_timestamp_perf_counter_ns(timestamp)def log_new_timestamp_for_webcam_ns(self, webcam_id: str, timestamp: Union[float, int],frame_number: int = None):- self._webcam_timestamp_loggers[webcam_id].log_new_timestamp_ns(timestamp)+ self._webcam_timestamp_loggers[webcam_id].log_new_timestamp_perf_counter_ns(timestamp)if frame_number is not None:assert (self._webcam_timestamp_loggers[webcam_id].number_of_frames == frame_number,f"Numer of timestamps ({self._webcam_timestamp_loggers[webcam_id].number_of_frames}) logged does not match frame_number ({frame_number}) for: camera_{webcam_id}")@@ -140,7 +156,7 @@ class TimestampManager:this_multi_frame_timestamps = []for this_cam_id, this_cam_frame in this_multi_frame_dict.items():- this_multi_frame_timestamps.append(this_cam_frame.timestamp)+ this_multi_frame_timestamps.append(this_cam_frame.timestamp_in_seconds_from_record_start)return this_multi_frame_timestampsdiff --git a/src/freemocap_qt_gui/__init__.py b/src/freemocap_qt_gui/__init__.pynew file mode 100644index 00000000..e69de29bdiff --git a/src/freemocap_qt_gui/freemocap_qt_gui.py b/src/freemocap_qt_gui/freemocap_qt_gui.pynew file mode 100644index 00000000..6a7522b6--- /dev/null+++ b/src/freemocap_qt_gui/freemocap_qt_gui.py@@ -0,0 +1,214 @@+import logging+from contextlib import contextmanager+from typing import Dict++import numpy as np+from PyQt5.QtCore import Qt+from PyQt5.QtGui import QPixmap, QFont+from PyQt5.QtWidgets import QLineEdit, QFormLayout, QWidget, QVBoxLayout, QPushButton+from pyqtgraph.dockarea.DockArea import DockArea+from pyqtgraph.dockarea.Dock import Dock++from pyqtgraph.Qt import QtWidgets+import pyqtgraph as pg+from pyqtgraph.parametertree import ParameterTree, Parameter++from rich import print++from src.api.routes.session.session_router import SessionCalibrateModel, calibrate_session, record_session, \+ SessionIdModel+from src.cameras.detection.cam_singleton import get_or_create_cams+from src.cameras.multicam_manager.cv_camera_manager import OpenCVCameraManager+from src.config.home_dir import create_session_id+from src.config.webcam_config import WebcamConfig, webcam_config_to_qt_parameter_list++logger = logging.getLogger(__name__)++default_webcam_config = WebcamConfig()+++class FreemocapQtGUI:+ def __init__(self):+ self.pyqtgraph_app = pg.mkQApp('freemocap! :D')+ self._setup_and_launch()+ self._session_id = None+ self._shut_it_down = False+ self.gui_update_number = -1+ self._dictionary_of_available_webcams = {}+ self._available_cameras_data_tree_widget = None+ self._have_calibration_bool = False++ @property+ def session_id(self):+ return self._session_id++ @property+ def is_running(self):+ return not self._shut_it_down++ def run(self):+ logger.info('launching freemocap GUI')+ self._setup_and_launch()++ def update(self):+ self.gui_update_number += 1+ if self.gui_update_number % 1000:+ print(f"gui update number: {self.gui_update_number})")++ def _setup_and_launch(self):+ self._setup_main_window()+ self._setup_welcome_panel()+ self._main_window_widget.show()++ def _setup_main_window(self, window_width: int = 300, 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`+ """+ self._main_window_width = window_width+ self._main_window_height = window_height++ self._main_window_widget = QtWidgets.QMainWindow()+ self._main_window_widget.resize(self._main_window_width , self._main_window_height)++ self._main_dock_area = DockArea()+ self._main_window_widget.setCentralWidget(self._main_dock_area)+ self._main_window_widget.setWindowTitle('freemocap πβ¨')++ def _setup_welcome_panel(self):+ self._welcome_panel_dock = Dock("freemocap", size=(1, 1))+ self._welcome_panel_layout_widget = pg.LayoutWidget()+ self._welcome_panel_dock.addWidget(self._welcome_panel_layout_widget)+ self._main_dock_area.addDock(self._welcome_panel_dock, size=(1, 1))++ welcome_label = QtWidgets.QLabel("Welcome to Freemocap πβ¨")+ self._welcome_panel_layout_widget.addWidget(welcome_label, row='next')++ session_id_layout = QFormLayout()+ self.session_id_line_edit = QLineEdit(create_session_id())+ session_id_layout.addRow("session_id: ", self.session_id_line_edit)+ session_id_widget = QWidget()+ session_id_widget.setLayout(session_id_layout)+ self._welcome_panel_layout_widget.addWidget(session_id_widget, row='next')++ self._start_button = QtWidgets.QPushButton('Start new session')+ self._start_button.setEnabled(True)+ self._start_button.clicked.connect(self._start)++ self._welcome_panel_layout_widget.addWidget(self._start_button, row='next')++ def _create_setup_control_panel(self):+ self._main_window_widget.resize(self._main_window_width+100, 400)+ self._setup_panel_dock = Dock("Setup π οΈ")+ self._setup_panel_layout_widget = pg.LayoutWidget()+ self._setup_panel_dock.addWidget(self._setup_panel_layout_widget)+ self._main_dock_area.addDock(self._setup_panel_dock,+ 'bottom',+ self._welcome_panel_dock)++ self._detect_cameras_button = QtWidgets.QPushButton('Detect Available Cameras ππ₯')+ 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)++ self.hint_label = QtWidgets.QLabel("HINT - Keep an eye on your `terminal` for helpful `log` statements ;D")+ self.hint_label.hide()+ self._setup_panel_layout_widget.addWidget(self.hint_label, row=1, col=0)++ self._calibrate_cameras_button = QtWidgets.QPushButton('Record Camera Calibration Videos π₯ π')+ self._calibrate_cameras_button.setEnabled(True)+ self._calibrate_cameras_button.clicked.connect(self._record_calibration_videos)+ self._calibrate_cameras_button.hide()+ self._setup_panel_layout_widget.addWidget(self._calibrate_cameras_button, row=0, col=1)++ self._use_previous_calibration_checkbox = QtWidgets.QCheckBox("Use Previous Calibration π₯ β³")+ self._use_previous_calibration_checkbox.setChecked(False)+ self._use_previous_calibration_checkbox.stateChanged.connect(self._check_if_have_calibration)+ 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('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._lock_in_session_id(self.session_id_line_edit.text())+ # self._start_button.setText("Reset π«")+ self._start_button.hide()+ 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)+ # record new session\+ record_session(session_id_model)++ def _record_calibration_videos(self):+ logger.debug("`launch camera windows` button pressed")+ # #calibrate_session+ session_calibrate_model = SessionCalibrateModel(session_id=self._session_id,+ charuco_square_size=39)+ calibrate_session(session_calibrate_model)+ self._have_calibration_bool = True++ def _detect_available_cameras(self):+ logger.debug("`Detect Available Cameras` button was pressed")+ self.hint_label.show()+ self._detect_cameras_button.setText("Detecting available cameras....")+ self.pyqtgraph_app.processEvents()++ self._opencv_camera_manager = OpenCVCameraManager(self.session_id)+ self._dictionary_of_available_webcams = self._opencv_camera_manager.get_available_cameras()++ logger.debug(+ f"`get_or_create_cams()` returned:_available_cameras_dictionary {self._dictionary_of_available_webcams}")+ self._detect_cameras_button.setText('Re-Detect Available Cameras ππ₯')+ self.hint_label.hide()++ if self._available_cameras_data_tree_widget is None:+ self.camera_setup_parameter_tree_widget = ParameterTree()+ self._setup_panel_layout_widget.addWidget(self.camera_setup_parameter_tree_widget, col=0, row=1)++ self._update_webcam_config_parameter_tree(self._dictionary_of_available_webcams)+ # self._launch_camera_windows_button.show()+ self._calibrate_cameras_button.show()+ self._use_previous_calibration_checkbox.show()++ def _update_webcam_config_parameter_tree(self,+ dictionary_of_available_webcams: Dict[str, WebcamConfig]):+ list_of_webcam_parameters_groups = []+ for this_webcam_id, this_webcam_config in dictionary_of_available_webcams.items():+ this_webcam_parameters_list = webcam_config_to_qt_parameter_list(this_webcam_config)++ list_of_webcam_parameters_groups.append(Parameter.create(name=f"Webcam: {this_webcam_id}", type='group',+ children=this_webcam_parameters_list))++ available_webcam_parameters_group = Parameter.create(name=f"Available Cameras", type='group',+ children=list_of_webcam_parameters_groups)++ self.camera_setup_parameter_tree_widget.setParameters(available_webcam_parameters_group)++ def _lock_in_session_id(self, session_id: str):+ self._session_id = session_id+ self.session_id_line_edit.setReadOnly(True)+ self.session_id_line_edit.setStyleSheet("QLineEdit"+ "{"+ "background : lightgrey;"+ "}")++ def _reset(self):+ print('i dont know how to reset things lol')+++if __name__ == "__main__":+ gui = FreemocapQtGUI()+ pg.exec()diff --git a/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.py b/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.pyindex 29116972..ef83da31 100644--- a/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.py+++ b/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.py@@ -1572,7 +1572,7 @@ class CameraGroup:if init_extrinsics:rtvecs = extract_rtvecs(merged)if verbose:- pprint(get_connections(rtvecs, self.get_names()))+ print(get_connections(rtvecs, self.get_names()))rvecs, tvecs = get_initial_extrinsics(rtvecs)self.set_rotations(rvecs)self.set_translations(tvecs)diff --git a/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py b/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.pyindex bcd54e02..daae9324 100644--- a/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py+++ b/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py@@ -83,7 +83,7 @@ class CalibrationPipelineOrchestrator:continue# log timestamp- this_cam_this_frame_timestamp_ns = this_cam_latest_frame.timestamp+ this_cam_this_frame_timestamp_ns = this_cam_latest_frame.timestamp_in_seconds_from_record_startthis_cam_this_frame_number = this_cam_latest_frame.frame_numbertimestamp_manager.log_new_timestamp_for_webcam_ns(this_webcam_id,this_cam_this_frame_timestamp_ns,@@ -130,7 +130,7 @@ class CalibrationPipelineOrchestrator:cv2.destroyAllWindows()for this_open_cv_camera in connected_cameras_dict.values():if not save_video_in_frame_loop:- this_open_cv_camera.video_recorder.save_list_of_frames_to_list_to_video_file(this_open_cv_camera.frame_list)+ this_open_cv_camera.video_recorder.save_list_of_frames_to_video_file(this_open_cv_camera.video_recorder.frame_list)this_open_cv_camera.video_recorder.close()if show_visualizer_gui:diff --git a/src/pipelines/session_pipeline/session_pipeline_orchestrator.py b/src/pipelines/session_pipeline/session_pipeline_orchestrator.pyindex 5850465e..489833d4 100644--- a/src/pipelines/session_pipeline/session_pipeline_orchestrator.py+++ b/src/pipelines/session_pipeline/session_pipeline_orchestrator.py@@ -116,7 +116,7 @@ class SessionPipelineOrchestrator:frame_width=cv_cam.image_width(),frame_height=cv_cam.image_height(),)- writer.save_list_of_frames_to_list_to_video_file(options)+ writer.save_list_of_frames_to_video_file(options)def calibrate_camera_capture_volume(self, use_most_recent_calibration: bool = False,load_calibration_from_session_id: str = None,@@ -144,7 +144,7 @@ class SessionPipelineOrchestrator:self,show_visualizer_gui=True,show_camera_views_in_windows=False,- detect_mediapipe=True,+ detect_mediapipe=False,detect_charuco=True,reconstruct_3d=True,save_video=True,@@ -210,7 +210,7 @@ class SessionPipelineOrchestrator:image_to_display = this_cam_latest_frame.image.copy()# log timestamp- this_cam_this_frame_timestamp_ns = this_cam_latest_frame.timestamp+ this_cam_this_frame_timestamp_ns = this_cam_latest_frame.timestamp_in_seconds_from_record_startthis_cam_this_frame_number = this_cam_latest_frame.frame_numbertimestamp_manager.log_new_timestamp_for_webcam_ns(this_webcam_id,this_cam_this_frame_timestamp_ns,@@ -292,7 +292,7 @@ class SessionPipelineOrchestrator:traceback.print_exc()finally:for this_open_cv_camera in connected_cameras_dict.values():- this_open_cv_camera.video_recorder.save_list_of_frames_to_list_to_video_file(this_open_cv_camera.frame_list)+ this_open_cv_camera.video_recorder.save_list_of_frames_to_video_file(this_open_cv_camera.frame_list)if show_camera_views_in_windows:logger.info(f"Destroy window {this_open_cv_camera.webcam_id_as_str}")diff --git a/src/tests/video_writer/test_video_writer.py b/src/tests/video_writer/test_video_writer.pyindex 81b95fe8..e6c1b619 100644--- a/src/tests/video_writer/test_video_writer.py+++ b/src/tests/video_writer/test_video_writer.py@@ -43,7 +43,7 @@ class VideoWriterTestCase(TestCase):fps=1,)- vw.save_list_of_frames_to_list_to_video_file(save_options)+ vw.save_list_of_frames_to_video_file(save_options)expected_path = Path().joinpath(file_path, "movie.mp4")assert save_options.full_path == expected_path, "Paths do not match"