Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

Jon/gui/lets make a working pipeline (#221)

jonmatthis996f17f4c2fa
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 669e2d21..2d37eeb1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -3,7 +3,7 @@ name: ci
on:
push:
branches:
- - main
+ - icis_conference_main
jobs:
deploy:
runs-on: ubuntu-latest
diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.yml
index f56e046f..ec8fdbde 100755
--- a/.github/workflows/python-testing.yml
+++ b/.github/workflows/python-testing.yml
@@ -2,7 +2,7 @@ name: Freemocap Tests
on:
pull_request:
- branches: [ main ]
+ branches: [ icis_conference_main ]
paths:
- src
diff --git a/assets/logo/freemocap-logo-white-border.png b/assets/logo/freemocap-logo-white-border.png
deleted file mode 100644
index 5a7b06a7..00000000
Binary files a/assets/logo/freemocap-logo-white-border.png and /dev/null differ
diff --git a/assets/logo/fmc-logo-black-border-white-bkgd.png b/assets/logo/freemocap-skelly-logo-black-border-white-bkgd.png
similarity index 100%
rename from assets/logo/fmc-logo-black-border-white-bkgd.png
rename to assets/logo/freemocap-skelly-logo-black-border-white-bkgd.png
diff --git a/freemocap-ui/src/services/supported_recorder.ts b/freemocap-ui/src/services/supported_recorder.ts
index 6d704c32..63cf7203 100644
--- a/freemocap-ui/src/services/supported_recorder.ts
+++ b/freemocap-ui/src/services/supported_recorder.ts
@@ -14,10 +14,10 @@ export function supported() {
// // `${mimeType};codecs:${codec.toUpperCase()}`
// ].forEach(variation => {
// if(isSupported(variation))
-// supported.push(variation);
+// supported.push_variables(variation);
// }));
// if (isSupported(mimeType))
-// supported.push(mimeType);
+// supported.push_variables(mimeType);
// });
// return supported;
// };
diff --git a/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx b/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx
index a6a05788..a59c82e8 100644
--- a/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx
+++ b/freemocap-ui/src/views/prod/SetupAndPreviewCamera.tsx
@@ -20,7 +20,7 @@ export const SetupAndPreviewCamera = (props: Props) => {
<Box>
<Box display={'flex'} flexDirection={'column'} width={400}>
<Button>Preview in CV2</Button>
- {!frameCapture.isConnectionClosed && <img src={data} alt={"video capture"} />}
+ {!frameCapture.isConnectionClosed && <img src={data} alt={"video start"} />}
</Box>
<ConfigForm onSubmit={onSubmit}/>
</Box>
diff --git a/requirements.txt b/requirements.txt
index 2aacd93e..7024a71a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -29,3 +29,5 @@ pyinstaller==5.2
pyinstaller-hooks-contrib==2022.8
black[d]==22.6.0
mkdocs-material==8.3.9
+qtconsole==5.3.0
+qtpy==2.0.1
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 5aa27738..da46c930 100644
--- a/setup.py
+++ b/setup.py
@@ -42,7 +42,7 @@ setup(
name="freemocap",
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
- description="The FreeMoCap Project: A free-and-open-source, hardware-and-software-agnostic, minimal-cost, research-grade, motion capture system and platform for decentralized scientific research, education, and training",
+ description="The FreeMoCap Project: A free-and-open-source, hardware-and-software-agnostic, minimal-cost, research-grade, motion start system and platform for decentralized scientific research, education, and training",
long_description=readme,
author="Jonathan Samir Matthis",
author_email="[email protected]",
@@ -63,9 +63,13 @@ setup(
]
},
install_requires=requirements,
- extras_require={"dlc": ["tensorflow-gpu>=2.0",
- "tf_slim>=1.1.0",
- "deeplabcut>=2.2",]},
+ extras_require={
+ "dlc": [
+ "tensorflow-gpu>=2.0",
+ "tf_slim>=1.1.0",
+ "deeplabcut>=2.2",
+ ]
+ },
license="AGPLv3",
classifiers=[
"Development Status :: 2 - Pre-Alpha",
diff --git a/src/api/routes/session/session_router.py b/src/api/routes/session/session_router.py
index d8a399cc..bbe913a1 100644
--- a/src/api/routes/session/session_router.py
+++ b/src/api/routes/session/session_router.py
@@ -12,12 +12,12 @@ from jon_scratch.pupil_calibration_pipeline.qt_gl_laser_skeleton_visualizer impo
from src.cameras.launch_camera_frame_loop import launch_camera_frame_loop
from src.cameras.multicam_manager.cv_camera_manager import OpenCVCameraManager
from src.config.home_dir import (
- create_session_id,
+ create_default_session_id,
get_session_folder_path,
get_most_recent_session_id,
create_session_folder,
)
-from src.core_processor.mediapipe_skeleton_detector.mediapipe_skeleton_detector import (
+from src.core_processes.mediapipe_2d_skeleton_detector.mediapipe_skeleton_detector import (
MediaPipeSkeletonDetector,
)
from src.pipelines.calibration_pipeline.calibration_pipeline_orchestrator import (
@@ -75,7 +75,7 @@ class SessionIdModel(BaseModel):
async def create_session(
session_create_model: SessionCreateModel = SessionCreateModel(),
) -> SessionResponse:
- session_id = create_session_id()
+ session_id = create_default_session_id()
if session_create_model.user_session_tag_str is not None:
session_id = session_id + session_create_model.user_session_tag_str
@@ -90,7 +90,7 @@ async def create_session(
def 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"""
+ """calibate start 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"""
session_id = session_calibrate_model.session_id
if session_id is None or session_id == "string":
@@ -191,8 +191,8 @@ def visualize_session_offline(session_id_model: SessionIdModel = None):
if __name__ == "__main__":
- # # create_session
- # session_id_in = create_session_id('session_router_as_main')
+ # # create_blend_file_from_session_data
+ # session_id_in = create_default_session_id('session_router_as_main')
# session_id_model = SessionIdModel(session_id=session_id_in)
#
# # # #calibrate_session
diff --git a/src/cameras/capture/opencv_camera/opencv_camera.py b/src/cameras/capture/opencv_camera/opencv_camera.py
index d56d7e81..8960c55d 100644
--- a/src/cameras/capture/opencv_camera/opencv_camera.py
+++ b/src/cameras/capture/opencv_camera/opencv_camera.py
@@ -8,46 +8,36 @@ from typing import List, Union
import cv2
from src.cameras.capture.dataclasses.frame_payload import FramePayload
-from src.cameras.persistence.video_writer.video_recorder import VideoRecorder
from src.cameras.viewer.cv_cam_viewer import CvCamViewer
from src.config.webcam_config import WebcamConfig
from src.cameras.capture.opencv_camera.camera_stream_thread_handler import (
VideoCaptureThread,
)
-from src.core_processor.timestamp_manager.timestamp_manager import TimestampLogger
+from src.core_processes.timestamp_manager.timestamp_manager import TimestampLogger
logger = logging.getLogger(__name__)
class OpenCVCamera:
"""
- Performant implementation of video capture against webcams
+ Performant implementation of video start against webcams
"""
def __init__(
self,
config: WebcamConfig,
- session_id: str = None,
session_start_time_perf_counter_ns: int = 0,
calibration_video_bool: bool = False,
):
self._config = config
self._name = f"Camera_{self._config.webcam_id}"
self._opencv_video_capture_object: cv2.VideoCapture = None
- self._video_recorder: VideoRecorder = None
self._running_thread: VideoCaptureThread = None
self._new_frame_ready = False
self._number_of_frames_recorded = 0
self._calibration_video_bool = calibration_video_bool
- self._session_id = session_id
self._session_start_time_perf_counter_ns = session_start_time_perf_counter_ns
- @property
- def session_id(self):
- if self._session_id is None:
- return False
- return self._session_id
-
@property
def new_frame_ready(self):
"""
@@ -123,23 +113,6 @@ class OpenCVCamera:
logger.debug(f"Camera found at port number {self._config.webcam_id}")
- if self.session_id is False:
- logger.info(
- f"No `session_id` specified for {self._name}, video_recorder will not be created (because we won't know where to save the videos)"
- )
- self._video_recorder = None
- else:
- image_height = image.shape[0]
- image_width = image.shape[1]
-
- self._video_recorder = VideoRecorder(
- self._name,
- image_width=image_width,
- image_height=image_height,
- session_id=self.session_id,
- calibration_video_bool=self._calibration_video_bool,
- )
-
return success
def start_frame_capture_thread(self):
@@ -148,9 +121,7 @@ class OpenCVCamera:
f"Already capturing frames for webcam_id: {self.webcam_id_as_str}"
)
return
- logger.info(
- f"Beginning frame capture thread for webcam: {self.webcam_id_as_str}"
- )
+ logger.info(f"Beginning frame start thread for webcam: {self.webcam_id_as_str}")
self._running_thread = self._create_thread()
self._running_thread.start()
diff --git a/src/cameras/detection/cam_detection.py b/src/cameras/detection/cam_detection.py
index 5c62403f..d1e8bb22 100644
--- a/src/cameras/detection/cam_detection.py
+++ b/src/cameras/detection/cam_detection.py
@@ -5,7 +5,7 @@ import cv2
from src.cameras.detection.models import FoundCamerasResponse, RawCamera
-CAM_CHECK_NUM = 20
+CAM_CHECK_NUM = 20 # please give me a reason to increase this number ;D
logger = logging.getLogger(__name__)
@@ -19,11 +19,12 @@ class DetectPossibleCameras:
cap = cv2.VideoCapture(cam_id, cv2_backend)
success, image = cap.read()
- if success and image is not None:
- try:
- cams_to_use_list.append(RawCamera(webcam_id=str(cam_id)))
- finally:
- cap.release()
+ if success:
+ if image is not None:
+ try:
+ cams_to_use_list.append(RawCamera(webcam_id=str(cam_id)))
+ finally:
+ cap.release()
return FoundCamerasResponse(
number_of_cameras_found=len(cams_to_use_list),
diff --git a/src/cameras/detection/cam_singleton.py b/src/cameras/detection/cam_singleton.py
index 9a82f4d4..4e97a256 100644
--- a/src/cameras/detection/cam_singleton.py
+++ b/src/cameras/detection/cam_singleton.py
@@ -14,3 +14,15 @@ def get_or_create_cams(always_create=False):
_available_cameras = d.find_available_cameras()
return _available_cameras
+
+
+def get_or_create_cams_list(always_create=False):
+ """
+ same as `get_or_create_cams` but returns a list of camera ids instead of a FoundCamerasResponse object
+ """
+ found_cameras_response = get_or_create_cams(always_create=always_create)
+ available_cameras_list = [
+ this_cam.webcam_id for this_cam in found_cameras_response.cameras_found_list
+ ]
+
+ return available_cameras_list
diff --git a/src/cameras/launch_camera_frame_loop.py b/src/cameras/launch_camera_frame_loop.py
index 95ab1fb6..518e9559 100644
--- a/src/cameras/launch_camera_frame_loop.py
+++ b/src/cameras/launch_camera_frame_loop.py
@@ -10,8 +10,8 @@ from src.cameras.multicam_manager.cv_camera_manager import OpenCVCameraManager
from src.config.webcam_config import WebcamConfig
import asyncio
-from src.core_processor.show_cam_window import show_cam_window
-from src.core_processor.utils.image_fps_writer import write_fps_to_image
+from src.core_processes.show_cam_window import show_cam_window
+from src.core_processes.utils.image_fps_writer import write_fps_to_image
from src.pipelines.calibration_pipeline.charuco_board_detection.charuco_board_detector import (
CharucoBoardDetector,
)
@@ -94,10 +94,8 @@ def launch_camera_frame_loop(
if detect_charuco_in_image:
# detect charuco board
- this_charuco_frame_payload = (
- charuco_board_detector.detect_charuco_board(
- this_cam_latest_frame
- )
+ this_charuco_frame_payload = charuco_board_detector.detect_charuco_board_in_frame_payload(
+ this_cam_latest_frame
)
image_to_display = (
this_charuco_frame_payload.annotated_image.copy()
diff --git a/src/cameras/multicam_manager/cv_camera_manager.py b/src/cameras/multicam_manager/cv_camera_manager.py
index 5afbcc14..c925a4c2 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 OpenCVCamera
from src.cameras.detection.cam_singleton import get_or_create_cams
from src.cameras.persistence.video_writer.video_recorder import VideoRecorder
from src.config.webcam_config import WebcamConfig
-from src.core_processor.timestamp_manager.timestamp_manager import (
+from src.core_processes.timestamp_manager.timestamp_manager import (
TimestampManager,
TimestampLogger,
)
@@ -114,7 +114,7 @@ class OpenCVCameraManager:
) -> ContextManager[CamAndWriterResponse]:
"""
Context manager for easy start up, usage, and cleanup of camera resources.
- Can capture frames from a single webcam or all webcams detected.
+ Can start frames from a single webcam or all webcams detected.
"""
cv_camera = self._create_single_opencv_cam(webcam_id)
@@ -125,7 +125,7 @@ class OpenCVCameraManager:
yield CamAndWriterResponse(cv_camera=cv_camera)
self._stop_frame_capture([cv_camera])
except:
- logger.error("Printing traceback from starting capture session by cam")
+ logger.error("Printing traceback from starting start session by cam")
traceback.print_exc()
@contextmanager
@@ -152,7 +152,7 @@ class OpenCVCameraManager:
self._stop_frame_capture(open_cv_camera_objects)
except:
- logger.error("Printing traceback from starting capture session by cam")
+ logger.error("Printing traceback from starting start session by cam")
traceback.print_exc()
def _create_opencv_cameras(
diff --git a/src/cameras/persistence/video_writer/video_recorder.py b/src/cameras/persistence/video_writer/video_recorder.py
index 17c6e84a..4c0eab3c 100644
--- a/src/cameras/persistence/video_writer/video_recorder.py
+++ b/src/cameras/persistence/video_writer/video_recorder.py
@@ -17,46 +17,15 @@ from src.config.home_dir import (
get_calibration_videos_folder_path,
get_mediapipe_annotated_videos_folder_path,
)
-from rich.progress import Progress
logger = logging.getLogger(__name__)
class VideoRecorder:
- def __init__(
- self,
- video_name: str,
- image_width: int,
- image_height: int,
- session_id: str,
- fourcc: str = "MP4V",
- calibration_video_bool: bool = False,
- mediapipe_annotated_video_bool: bool = False,
- ):
- self._video_name = video_name
- self._image_width = image_width
- self._image_height = image_height
- self._fourcc = fourcc
+ def __init__(self):
+
self._frame_payload_list: List[FramePayload] = []
self._timestamps_npy = np.empty(0)
- self._cv2_video_writer = None
-
- # get yr paths straight
- self._session_id = session_id
-
- self._mediapipe_annotated_video_bool = mediapipe_annotated_video_bool
-
- @property
- def video_name(self):
- return self._video_name
-
- @property
- def video_folder_path(self):
- return self._video_folder_path
-
- @property
- def path_to_save_video_file(self):
- return self._path_to_save_video_file
@property
def frame_count(self):
@@ -66,12 +35,6 @@ class VideoRecorder:
def frame_list(self):
return self._frame_payload_list
- def save_frame_payload_to_video_file(self, frame_payload: FramePayload):
- if self._cv2_video_writer is None:
- self._initialize_video_writer()
-
- self._cv2_video_writer.write(frame_payload.image)
-
def close(self):
self._cv2_video_writer.release()
@@ -80,66 +43,74 @@ class VideoRecorder:
def save_list_of_frames_to_video_file(
self,
- list_of_frames: List[FramePayload] = None,
+ list_of_frames: List[FramePayload],
+ path_to_save_video_file: Union[str, Path],
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
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))
-
- self._initialize_video_writer(
- frames_per_second=frames_per_second, calibration_videos=calibration_videos
+ try:
+ frames_per_second = np.nanmedian((np.diff(self._timestamps_npy) ** -1))
+ except Exception as e:
+ logger.debug("Error calculating frames per second")
+ traceback.print_exc()
+ raise e
+
+ self._path_to_save_video_file = path_to_save_video_file
+
+ self._cv2_video_writer = self._initialize_video_writer(
+ image_height=list_of_frames[0].image.shape[0],
+ image_width=list_of_frames[0].image.shape[1],
+ frames_per_second=frames_per_second,
)
self._write_frame_list_to_video_file(list_of_frames)
- self._save_timestamps(self._timestamps_npy)
+ self._save_timestamps(timestamps_npy=self._timestamps_npy)
+ self._cv2_video_writer.release()
def save_image_list_to_disk(
- self, image_list: List[np.ndarray], frames_per_second: float
+ self,
+ image_list: List[np.ndarray],
+ path_to_save_video_file: Union[str, Path],
+ frames_per_second: float,
):
+
+ self._path_to_save_video_file = path_to_save_video_file
+
if len(image_list) == 0:
- logging.error(f"No frames to save for : {self._video_name}")
+ logging.error(f"No frames to save for : {self._path_to_save_video_file}")
return
- self._initialize_video_writer(frames_per_second=frames_per_second)
+ self._cv2_video_writer = self._initialize_video_writer(
+ image_height=image_list[0].shape[0],
+ image_width=image_list[0].shape[1],
+ frames_per_second=frames_per_second,
+ )
self._write_image_list_to_video_file(image_list)
def _initialize_video_writer(
self,
+ image_height: Union[int, float],
+ image_width: Union[int, float],
frames_per_second: Union[int, float] = None,
- calibration_videos: bool = False,
- ):
+ fourcc: str = "MP4V",
+ # calibration_videos: bool = False,
+ ) -> cv2.VideoWriter:
- video_file_name = self._video_name + ".mp4"
+ video_writer_object = cv2.VideoWriter(
+ str(self._path_to_save_video_file),
+ cv2.VideoWriter_fourcc(*fourcc),
+ frames_per_second,
+ (int(image_width), int(image_height)),
+ )
- if calibration_videos:
- self._video_folder_path = Path(
- get_calibration_videos_folder_path(self._session_id)
- )
- elif self._mediapipe_annotated_video_bool:
- self._video_folder_path = Path(
- get_mediapipe_annotated_videos_folder_path(self._session_id)
- )
- else:
- self._video_folder_path = Path(
- get_synchronized_videos_folder_path(self._session_id)
+ if not video_writer_object.isOpened():
+ logger.error(
+ f"cv2.VideoWriter failed to initialize for: {str(self._path_to_save_video_file)}"
)
+ raise Exception
- self._path_to_save_video_file = self._video_folder_path / video_file_name
-
- self._cv2_video_writer = cv2.VideoWriter(
- str(self.path_to_save_video_file),
- cv2.VideoWriter_fourcc(*self._fourcc),
- frames_per_second,
- (int(self._image_width), int(self._image_height)),
- )
+ return video_writer_object
def _write_frame_list_to_video_file(self, list_of_frames: List[FramePayload]):
try:
@@ -147,26 +118,26 @@ class VideoRecorder:
self._cv2_video_writer.write(frame.image)
except Exception as e:
- logger.debug("Failed during save in video writer")
+ logger.error(
+ f"Failed during save in video writer for video {str(self._path_to_save_video_file)}"
+ )
traceback.print_exc()
raise e
finally:
- logger.info(f"Saved video to path: {self.path_to_save_video_file}")
+ logger.info(f"Saved video to path: {self._path_to_save_video_file}")
self._cv2_video_writer.release()
def _write_image_list_to_video_file(self, image_list: List[np.ndarray]):
try:
for image in image_list:
self._cv2_video_writer.write(image)
-
except Exception as e:
logger.error(
- f"Failed during save in video writer: {self.path_to_save_video_file}"
+ f"Failed during save in video writer for video {str(self._path_to_save_video_file)}"
)
traceback.print_exc()
raise e
finally:
- logger.info(f"Saved video to path: {self.path_to_save_video_file}")
self._cv2_video_writer.release()
def _gather_timestamps(self, list_of_frames: List[FramePayload]) -> np.ndarray:
@@ -182,13 +153,22 @@ class VideoRecorder:
return timestamps_npy
def _save_timestamps(self, timestamps_npy: np.ndarray):
- timestamp_file_name_npy = self._video_name + "_timestamps_binary.npy"
- timestamp_npy_full_save_path = self._video_folder_path / timestamp_file_name_npy
- np.save(str(timestamp_npy_full_save_path), timestamps_npy)
- logger.info(f"Saved timestamps to path: {timestamp_file_name_npy}")
+ timestamp_folder_path = self._path_to_save_video_file.parent / "timestamps"
+ timestamp_folder_path.mkdir(parents=True, exist_ok=True)
+
+ base_timestamp_path_str = str(
+ timestamp_folder_path / self._path_to_save_video_file.stem
+ )
- timestamp_file_name_csv = self._video_name + "_timestamps_human_readable.csv"
- timestamp_csv_full_save_path = self._video_folder_path / timestamp_file_name_csv
+ # save timestamps to npy (binary) file (via numpy.ndarray)
+ path_to_save_timestamps_npy = base_timestamp_path_str + "_binary.npy"
+ np.save(str(path_to_save_timestamps_npy), timestamps_npy)
+ logger.info(f"Saved timestamps to path: {str(path_to_save_timestamps_npy)}")
+
+ # save timestamps to human readable (csv/text) file (via pandas.DataFrame)
+ path_to_save_timestamps_csv = (
+ base_timestamp_path_str + "_timestamps_human_readable.csv"
+ )
timestamp_dataframe = pd.DataFrame(timestamps_npy)
- timestamp_dataframe.to_csv(str(timestamp_csv_full_save_path))
- logger.info(f"Saved timestamps to path: {timestamp_file_name_csv}")
+ timestamp_dataframe.to_csv(str(path_to_save_timestamps_csv))
+ logger.info(f"Saved timestamps to path: {str(path_to_save_timestamps_csv)}")
diff --git a/src/cameras/save_synchronized_videos.py b/src/cameras/save_synchronized_videos.py
index 51110541..5d7bfbb9 100644
--- a/src/cameras/save_synchronized_videos.py
+++ b/src/cameras/save_synchronized_videos.py
@@ -1,22 +1,28 @@
-from typing import List
+from pathlib import Path
+from typing import List, Union, Dict
import numpy as np
from src.cameras.capture.dataclasses.frame_payload import FramePayload
from src.cameras.persistence.video_writer.video_recorder import VideoRecorder
-from src.gui.main.state.app_state import APP_STATE
+from src.gui.icis_conference_main.state.app_state import APP_STATE
+
+import logging
+
+logger = logging.getLogger(__name__)
def save_synchronized_videos(
- list_of_video_recorders: List[VideoRecorder],
- calibration_videos: bool = False,
- mocap_videos: bool = False,
+ dictionary_of_video_recorders: Dict[str, VideoRecorder],
+ folder_to_save_videos=Union[str, Path],
):
+ logger.info(f"saving synchronized video to folder: {str(folder_to_save_videos)}")
+
each_cam_frame_list = []
first_frame_timestamps = []
final_frame_timestamps = []
- for video_recoder in list_of_video_recorders:
+ for video_recoder in dictionary_of_video_recorders.values():
cam_frame_list = video_recoder.frame_list
# first_frame_timestamps.append(cam_frame_list[0].timestamp_in_seconds_from_record_start)
# final_frame_timestamps.append(cam_frame_list[-1].timestamp_in_seconds_from_record_start)
@@ -29,13 +35,13 @@ def save_synchronized_videos(
latest_first_frame = np.max(first_frame_timestamps)
earliest_final_frame = np.min(final_frame_timestamps)
- print(f"first_frame_timestamps: {first_frame_timestamps}")
- print(f"np.diff(first_frame_timestamps): {np.diff(first_frame_timestamps)}")
- print(f"latest_first_frame: {latest_first_frame}")
+ logger.info(f"first_frame_timestamps: {first_frame_timestamps}")
+ logger.info(f"np.diff(first_frame_timestamps): {np.diff(first_frame_timestamps)}")
+ logger.info(f"latest_first_frame: {latest_first_frame}")
- print(f"final_frame_timestamps: {final_frame_timestamps}")
- print(f"np.diff(final_frame_timestamps): {np.diff(final_frame_timestamps)}")
- print(f"earliest_final_frame: {earliest_final_frame}")
+ logger.info(f"final_frame_timestamps: {final_frame_timestamps}")
+ logger.info(f"np.diff(final_frame_timestamps): {np.diff(final_frame_timestamps)}")
+ logger.info(f"earliest_final_frame: {earliest_final_frame}")
each_cam_clipped_frame_list = []
each_cam_clipped_timestamp_list = []
@@ -72,25 +78,26 @@ def save_synchronized_videos(
this_cam_synchronized_frame_list.append(closest_frame)
each_cam_synchronized_frame_list.append(this_cam_synchronized_frame_list)
- print(
+ logger.info(
f" (clipped) number_of_frames_per_camera: {number_of_frames_per_camera_clipped}, min:{min_number_of_frames}"
)
- if mocap_videos:
- APP_STATE.number_of_frames_in_the_mocap_videos = number_of_frames_per_camera
-
final_frame_timestamps = [
frame_list[-1].timestamp_unix_time_seconds
for frame_list in each_cam_synchronized_frame_list
]
- print(f"np.diff(final_frame_timestamps): {np.diff(final_frame_timestamps)}")
+ logger.info(f"np.diff(final_frame_timestamps): {np.diff(final_frame_timestamps)}")
- for video_recoder, frame_list in zip(
- list_of_video_recorders, each_cam_synchronized_frame_list
+ for camera_id, video_recoder, frame_list in zip(
+ dictionary_of_video_recorders.keys(),
+ dictionary_of_video_recorders.values(),
+ each_cam_synchronized_frame_list,
):
video_recoder.save_list_of_frames_to_video_file(
- list_of_frames=frame_list, calibration_videos=calibration_videos
+ list_of_frames=frame_list,
+ path_to_save_video_file=Path(folder_to_save_videos)
+ / f"Camera_{str(camera_id).zfill(3)}.mp4",
)
# create_timestamp_diagnostic_plots(final_frame_timestamps) #breadcrumbs for a future function to generate timestamp diagnostic plots
diff --git a/src/config/home_dir.py b/src/config/home_dir.py
index c76c54c4..636d252e 100644
--- a/src/config/home_dir.py
+++ b/src/config/home_dir.py
@@ -8,9 +8,10 @@ logger = logging.getLogger(__name__)
BASE_FOLDER_NAME = "freemocap_data"
MOST_RECENT_SESSION_ID_FILENAME = "most_recent_session_id.toml"
+CAMERA_CALIBRATION_FILE_NAME = "camera_calibration_data.toml"
-def create_session_id(string_tag: str = None):
+def create_default_session_id(string_tag: str = None):
session_id = "session_" + time.strftime("%m-%d-%Y-%H_%M_%S")
if string_tag is not None:
@@ -43,7 +44,10 @@ def os_independent_home_dir():
def get_freemocap_data_folder_path(create_folder: bool = True):
freemocap_data_folder_path = Path(os_independent_home_dir(), BASE_FOLDER_NAME)
- freemocap_data_folder_path.mkdir(exist_ok=create_folder, parents=True)
+
+ if create_folder:
+ freemocap_data_folder_path.mkdir(exist_ok=create_folder, parents=True)
+
return str(freemocap_data_folder_path)
@@ -92,7 +96,7 @@ def get_mediapipe_annotated_videos_folder_path(
return str(mediapipe_annotated_videos_path)
-def get_session_output_data_folder_path(session_id: str, create_folder: bool = True):
+def get_output_data_folder_path(session_id: str, create_folder: bool = True):
output_data_folder_path = (
Path(get_session_folder_path(session_id)) / "output_data_files"
)
@@ -101,9 +105,8 @@ def get_session_output_data_folder_path(session_id: str, create_folder: bool = T
return str(output_data_folder_path)
-def get_session_calibration_file_path(session_id: str) -> str:
- calibration_file_name = f"{session_id}_camera_calibration.toml"
+def get_session_calibration_toml_file_path(session_id: str) -> str:
calibration_file_path = (
- Path(get_session_folder_path(session_id)) / calibration_file_name
+ Path(get_session_folder_path(session_id)) / CAMERA_CALIBRATION_FILE_NAME
)
return str(calibration_file_path)
diff --git a/src/config/webcam_config.py b/src/config/webcam_config.py
index c2558167..53edde1c 100644
--- a/src/config/webcam_config.py
+++ b/src/config/webcam_config.py
@@ -14,35 +14,3 @@ 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
diff --git a/src/core_processor/__init__.py b/src/core_processes/__init__.py
similarity index 100%
rename from src/core_processor/__init__.py
rename to src/core_processes/__init__.py
diff --git a/src/core_processor/camera_calibration/__init__.py b/src/core_processes/capture_volume_calibration/__init__.py
similarity index 100%
rename from src/core_processor/camera_calibration/__init__.py
rename to src/core_processes/capture_volume_calibration/__init__.py
diff --git a/src/core_processor/camera_calibration/calibration_dataclasses.py b/src/core_processes/capture_volume_calibration/calibration_dataclasses.py
similarity index 100%
rename from src/core_processor/camera_calibration/calibration_dataclasses.py
rename to src/core_processes/capture_volume_calibration/calibration_dataclasses.py
diff --git a/src/core_processor/camera_calibration/calibration_diagnostics_visualizer.py b/src/core_processes/capture_volume_calibration/calibration_diagnostics_visualizer.py
similarity index 98%
rename from src/core_processor/camera_calibration/calibration_diagnostics_visualizer.py
rename to src/core_processes/capture_volume_calibration/calibration_diagnostics_visualizer.py
index f6b590d3..0532cafb 100644
--- a/src/core_processor/camera_calibration/calibration_diagnostics_visualizer.py
+++ b/src/core_processes/capture_volume_calibration/calibration_diagnostics_visualizer.py
@@ -7,7 +7,7 @@ from pyqtgraph.Qt import QtWidgets
import cv2
-from src.core_processor.camera_calibration.calibration_dataclasses import (
+from src.core_processes.capture_volume_calibration.calibration_dataclasses import (
CameraCalibrationData,
)
@@ -20,7 +20,7 @@ class CalibrationDiagnosticsVisualizer:
self.image_point_original = np.empty(0)
self.image_point_remapped = np.empty(0)
- # create main app and window
+ # create icis_conference_main app and window
self.pyqtgraph_app = pg.mkQApp("DockArea Example")
self.main_window_widget = QtWidgets.QMainWindow()
self.dock_area = DockArea()
diff --git a/src/core_processor/camera_calibration/camera_calibrator.py b/src/core_processes/capture_volume_calibration/camera_calibrator.py
similarity index 95%
rename from src/core_processor/camera_calibration/camera_calibrator.py
rename to src/core_processes/capture_volume_calibration/camera_calibrator.py
index ba39c5b6..d76b962b 100644
--- a/src/core_processor/camera_calibration/camera_calibrator.py
+++ b/src/core_processes/capture_volume_calibration/camera_calibrator.py
@@ -4,7 +4,7 @@ import cv2
from src.cameras.capture.dataclasses.frame_payload import FramePayload
from src.cameras.capture.opencv_camera.opencv_camera import OpenCVCamera
-from src.core_processor.camera_calibration.calibration_dataclasses import (
+from src.core_processes.capture_volume_calibration.calibration_dataclasses import (
CameraCalibrationData,
)
from src.pipelines.calibration_pipeline.charuco_board_detection.charuco_board_detector import (
@@ -39,8 +39,10 @@ class CameraCalibrator:
def _process_incoming_frame(self, raw_frame_payload: FramePayload):
- charuco_frame_payload = self._charuco_board_detector.detect_charuco_board(
- raw_frame_payload
+ charuco_frame_payload = (
+ self._charuco_board_detector.detect_charuco_board_in_frame_payload(
+ raw_frame_payload
+ )
)
charuco_view_data = charuco_frame_payload.charuco_view_data
diff --git a/src/core_processes/capture_volume_calibration/charuco_default_values.py b/src/core_processes/capture_volume_calibration/charuco_default_values.py
new file mode 100644
index 00000000..021eb9d7
--- /dev/null
+++ b/src/core_processes/capture_volume_calibration/charuco_default_values.py
@@ -0,0 +1 @@
+default_charuco_square_size_mm = 39
diff --git a/src/core_processes/capture_volume_calibration/get_anipose_calibration_object.py b/src/core_processes/capture_volume_calibration/get_anipose_calibration_object.py
new file mode 100644
index 00000000..4d2acbba
--- /dev/null
+++ b/src/core_processes/capture_volume_calibration/get_anipose_calibration_object.py
@@ -0,0 +1,44 @@
+import logging
+import shutil
+from pathlib import Path
+from typing import Union
+
+from src.config.home_dir import get_freemocap_data_folder_path
+from src.pipelines.calibration_pipeline.anipose_camera_calibration import (
+ freemocap_anipose,
+)
+
+logger = logging.getLogger(__name__)
+
+
+def load_most_recent_anipose_calibration_toml(
+ save_copy_of_calibration_to_this_path: Union[str, Path] = None
+):
+ session_calibration_file_path = Path(
+ get_freemocap_data_folder_path(), "last_successful_calibration.toml"
+ )
+ logger.info(
+ f"loading `most recent calibration from:{str(session_calibration_file_path)}"
+ )
+ if save_copy_of_calibration_to_this_path is not None:
+ shutil.copy(
+ str(session_calibration_file_path), save_copy_of_calibration_to_this_path
+ )
+
+ return freemocap_anipose.CameraGroup.load(str(session_calibration_file_path))
+
+
+def load_calibration_from_session_id(
+ session_calibration_file_path: Union[str, Path],
+):
+ logger.info(
+ f"loading camera calibration file from:{str(session_calibration_file_path)}"
+ )
+ try:
+
+ return freemocap_anipose.CameraGroup.load(str(session_calibration_file_path))
+ except Exception as e:
+ logger.error(
+ f"Failed to load anipose calibration info from {str(session_calibration_file_path)}"
+ )
+ raise e
diff --git a/src/core_processor/camera_calibration/lens_distortion_calibrator.py b/src/core_processes/capture_volume_calibration/lens_distortion_calibrator.py
similarity index 97%
rename from src/core_processor/camera_calibration/lens_distortion_calibrator.py
rename to src/core_processes/capture_volume_calibration/lens_distortion_calibrator.py
index d00815c9..7184ca14 100644
--- a/src/core_processor/camera_calibration/lens_distortion_calibrator.py
+++ b/src/core_processes/capture_volume_calibration/lens_distortion_calibrator.py
@@ -3,11 +3,11 @@ import numpy as np
from rich import print
from src.cameras.capture.dataclasses.frame_payload import FramePayload
-from src.core_processor.camera_calibration.calibration_dataclasses import (
+from src.core_processes.capture_volume_calibration.calibration_dataclasses import (
LensDistortionCalibrationData,
)
from src.pipelines.calibration_pipeline.charuco_board_detection import BoardDetector
-from src.core_processor.camera_calibration.calibration_diagnostics_visualizer import (
+from src.core_processes.capture_volume_calibration.calibration_diagnostics_visualizer import (
CalibrationDiagnosticsVisualizer,
)
from src.pipelines.calibration_pipeline.charuco_board_detection.dataclasses import (
@@ -38,8 +38,10 @@ class LensDistortionCalibrator:
def process_incoming_frame(self, raw_frame_payload: FramePayload):
- charuco_frame_payload = self._board_detector.detect_charuco_board(
- raw_frame_payload
+ charuco_frame_payload = (
+ self._board_detector.detect_charuco_board_in_frame_payload(
+ raw_frame_payload
+ )
)
charuco_view_data = charuco_frame_payload.charuco_view_data
diff --git a/src/core_processes/capture_volume_calibration/run_anipose_capture_volume_calibration.py b/src/core_processes/capture_volume_calibration/run_anipose_capture_volume_calibration.py
new file mode 100644
index 00000000..da7d83ce
--- /dev/null
+++ b/src/core_processes/capture_volume_calibration/run_anipose_capture_volume_calibration.py
@@ -0,0 +1,26 @@
+from pathlib import Path
+from typing import Union, Callable
+
+from src.pipelines.calibration_pipeline.anipose_camera_calibration.anipose_camera_calibration import (
+ AniposeCameraCalibrator,
+)
+from src.pipelines.calibration_pipeline.charuco_board_detection.dataclasses.charuco_board_definition import (
+ CharucoBoardDataClass,
+)
+
+
+def run_anipose_capture_volume_calibration(
+ charuco_square_size: float,
+ calibration_videos_folder_path: Union[str, Path],
+ pin_camera_0_to_origin: bool = True,
+ progress_callback: Callable[[str], None] = None,
+):
+ anipose_camera_calibrator = AniposeCameraCalibrator(
+ CharucoBoardDataClass(),
+ charuco_square_size=charuco_square_size,
+ calibration_videos_folder_path=calibration_videos_folder_path,
+ )
+ progress_callback("Endurance is great wow wow wow")
+ return anipose_camera_calibrator.calibrate_camera_capture_volume(
+ pin_camera_0_to_origin=pin_camera_0_to_origin
+ )
diff --git a/src/core_processes/capture_volume_calibration/triangulate_3d_data.py b/src/core_processes/capture_volume_calibration/triangulate_3d_data.py
new file mode 100644
index 00000000..a82e09db
--- /dev/null
+++ b/src/core_processes/capture_volume_calibration/triangulate_3d_data.py
@@ -0,0 +1,86 @@
+from pathlib import Path
+from typing import Union
+
+import numpy as np
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+def triangulate_3d_data(
+ anipose_calibration_object,
+ mediapipe_2d_data: np.ndarray,
+ output_data_folder_path: Union[str, Path],
+):
+ number_of_cameras = mediapipe_2d_data.shape[0]
+ number_of_frames = mediapipe_2d_data.shape[1]
+ number_of_tracked_points = mediapipe_2d_data.shape[2]
+ number_of_spatial_dimensions = mediapipe_2d_data.shape[3]
+
+ if not number_of_spatial_dimensions == 2:
+ logger.error(
+ f"This is supposed to be 2D data but, number_of_spatial_dimensions: {number_of_spatial_dimensions}"
+ )
+ raise Exception
+
+ # reshape data to collapse across 'frames' so it becomes [number_of_cameras,
+ # number_of_2d_points(numFrames*numPoints), XY]
+ data2d_flat = mediapipe_2d_data.reshape(number_of_cameras, -1, 2)
+
+ logger.info(
+ f"Reconstructing 3d points from 2d points with shape: "
+ f"number_of_cameras: {number_of_cameras},"
+ f" number_of_frames: {number_of_frames}, "
+ f" number_of_tracked_points: {number_of_tracked_points},"
+ f" number_of_spatial_dimensions: {number_of_spatial_dimensions}"
+ )
+
+ data3d_flat = anipose_calibration_object.triangulate(data2d_flat, progress=True)
+
+ data3d_reprojectionError_flat = anipose_calibration_object.reprojection_error(
+ data3d_flat, data2d_flat, mean=True
+ )
+
+ data3d_numFrames_numTrackedPoints_XYZ = data3d_flat.reshape(
+ number_of_frames, number_of_tracked_points, 3
+ )
+ data3d_numFrames_numTrackedPoints_reprojectionError = (
+ data3d_reprojectionError_flat.reshape(
+ number_of_frames, number_of_tracked_points
+ )
+ )
+
+ path_to_3d_data_npy = save_mediapipe_3d_data_to_npy(
+ data3d_numFrames_numTrackedPoints_XYZ=data3d_numFrames_numTrackedPoints_XYZ,
+ data3d_numFrames_numTrackedPoints_reprojectionError=data3d_numFrames_numTrackedPoints_reprojectionError,
+ output_data_folder_path=output_data_folder_path,
+ )
+
+ return path_to_3d_data_npy
+
+
+def save_mediapipe_3d_data_to_npy(
+ data3d_numFrames_numTrackedPoints_XYZ: np.ndarray,
+ data3d_numFrames_numTrackedPoints_reprojectionError: np.ndarray,
+ output_data_folder_path: Union[str, Path],
+):
+ # save spatial XYZ data
+ mediapipe_3dData_save_path = (
+ Path(output_data_folder_path)
+ / "mediapipe_3dData_numFrames_numTrackedPoints_spatialXYZ.npy"
+ )
+
+ logger.info(f"saving: {mediapipe_3dData_save_path}")
+ np.save(str(mediapipe_3dData_save_path), data3d_numFrames_numTrackedPoints_XYZ)
+
+ # save reprojection error
+ mediapipe_reprojection_error_save_path = (
+ Path(output_data_folder_path)
+ / "mediapipe_3dData_numFrames_numTrackedPoints_reprojectionError.npy"
+ )
+
+ logger.info(f"saving: {mediapipe_reprojection_error_save_path}")
+ np.save(
+ str(mediapipe_reprojection_error_save_path),
+ data3d_numFrames_numTrackedPoints_reprojectionError,
+ )
diff --git a/src/core_processor/experiments/mediapipe_testing.py b/src/core_processes/experiments/mediapipe_testing.py
similarity index 100%
rename from src/core_processor/experiments/mediapipe_testing.py
rename to src/core_processes/experiments/mediapipe_testing.py
diff --git a/src/core_processor/experiments/nested_thread_queue.py b/src/core_processes/experiments/nested_thread_queue.py
similarity index 100%
rename from src/core_processor/experiments/nested_thread_queue.py
rename to src/core_processes/experiments/nested_thread_queue.py
diff --git a/src/core_processor/experiments/threading_single_cam.py b/src/core_processes/experiments/threading_single_cam.py
similarity index 96%
rename from src/core_processor/experiments/threading_single_cam.py
rename to src/core_processes/experiments/threading_single_cam.py
index 92dda808..c3bae6ad 100644
--- a/src/core_processor/experiments/threading_single_cam.py
+++ b/src/core_processes/experiments/threading_single_cam.py
@@ -8,7 +8,7 @@ class WebcamStream:
def __init__(self, stream_id=0):
self.stream_id = stream_id # default is 0 for primary camera
- # opening video capture stream
+ # opening video start stream
self.vcap = cv2.VideoCapture(self.stream_id)
if self.vcap.isOpened() is False:
print("[Exiting]: Error accessing webcam stream.")
@@ -58,7 +58,7 @@ class WebcamStream:
def stop(self):
self.stopped = True
- # initializing and starting multi-threaded webcam capture input stream
+ # initializing and starting multi-threaded webcam start input stream
webcam_stream1 = WebcamStream(stream_id=0) # stream_id = 0 is for primary camera
diff --git a/src/core_processor/log_setup.py b/src/core_processes/log_setup.py
similarity index 100%
rename from src/core_processor/log_setup.py
rename to src/core_processes/log_setup.py
diff --git a/src/core_processes/mediapipe_2d_skeleton_detector/load_mediapipe2d_data.py b/src/core_processes/mediapipe_2d_skeleton_detector/load_mediapipe2d_data.py
new file mode 100644
index 00000000..8823f273
--- /dev/null
+++ b/src/core_processes/mediapipe_2d_skeleton_detector/load_mediapipe2d_data.py
@@ -0,0 +1,21 @@
+from pathlib import Path
+from typing import Union
+
+import logging
+
+import numpy as np
+
+logger = logging.getLogger(__name__)
+
+
+def load_mediapipe2d_data(output_data_folder_path: Union[str, Path]):
+ mediapipe2d_xy_file_path = (
+ Path(output_data_folder_path)
+ / "mediapipe_2dData_numCams_numFrames_numTrackedPoints_pixelXY.npy"
+ )
+ logger.info(f"loading: {mediapipe2d_xy_file_path}")
+ mediapipe2d_numCams_numFrames_numTrackedPoints_pixelXY = np.load(
+ str(mediapipe2d_xy_file_path)
+ )
+
+ return mediapipe2d_numCams_numFrames_numTrackedPoints_pixelXY
diff --git a/src/core_processor/mediapipe_skeleton_detector/medaipipe_tracked_points_names_dict.py b/src/core_processes/mediapipe_2d_skeleton_detector/medaipipe_tracked_points_names_dict.py
similarity index 100%
rename from src/core_processor/mediapipe_skeleton_detector/medaipipe_tracked_points_names_dict.py
rename to src/core_processes/mediapipe_2d_skeleton_detector/medaipipe_tracked_points_names_dict.py
diff --git a/src/core_processor/mediapipe_skeleton_detector/mediapipe_skeleton_detector.py b/src/core_processes/mediapipe_2d_skeleton_detector/mediapipe_skeleton_detector.py
similarity index 89%
rename from src/core_processor/mediapipe_skeleton_detector/mediapipe_skeleton_detector.py
rename to src/core_processes/mediapipe_2d_skeleton_detector/mediapipe_skeleton_detector.py
index 895634d1..5915fb0c 100644
--- a/src/core_processor/mediapipe_skeleton_detector/mediapipe_skeleton_detector.py
+++ b/src/core_processes/mediapipe_2d_skeleton_detector/mediapipe_skeleton_detector.py
@@ -12,12 +12,13 @@ from src.cameras.persistence.video_writer.video_recorder import VideoRecorder
from src.config.home_dir import (
get_session_folder_path,
get_synchronized_videos_folder_path,
- get_session_output_data_folder_path,
+ get_output_data_folder_path,
)
-from src.core_processor.mediapipe_skeleton_detector.medaipipe_tracked_points_names_dict import (
+from src.core_processes.mediapipe_2d_skeleton_detector.medaipipe_tracked_points_names_dict import (
mediapipe_tracked_point_names_dict,
)
-from src.gui.main.state.app_state import APP_STATE
+
+from src.gui.main.app_state.app_state import APP_STATE
logger = logging.getLogger(__name__)
@@ -79,7 +80,7 @@ class Mediapipe2dDataPayload:
class MediaPipeSkeletonDetector:
def __init__(self, session_id: str = None):
- self._session_id = session_id
+
self.model_complexity = 2 # can be 0,1, or 2 - higher numbers are more accurate but heavier computationally
self.min_detection_confidence = 0.5
self.min_tracking_confidence = 0.5
@@ -135,13 +136,9 @@ class MediaPipeSkeletonDetector:
def detect_skeleton_in_image(
self,
raw_image: np.ndarray = None,
- raw_frame_payload: FramePayload = None,
annotated_image: np.ndarray = None,
) -> Mediapipe2dDataPayload:
- if raw_frame_payload is not None:
- raw_image = raw_frame_payload.image.copy()
-
mediapipe_results = self._holistic_tracker.process(
raw_image
) # <-this is where the magic happens, i.e. where the raw image is processed by a convolutional neural network to provide an estimate of joint position in pixel coordinates. Please don't forget that this is insane and should not be possible lol
@@ -163,23 +160,25 @@ class MediaPipeSkeletonDetector:
)
return Mediapipe2dDataPayload(
- raw_frame_payload=raw_frame_payload,
mediapipe_results=mediapipe_results,
annotated_image=annotated_image,
pixel_data_numpy_arrays=mediapipe_single_frame_npy_data,
)
- def process_session_folder(self, save_annotated_videos: bool = True):
- synchronized_videos_path = Path(
- get_synchronized_videos_folder_path(self._session_id)
- )
- logger.info(f"loading synchronized videos from: {synchronized_videos_path}")
- each_video_frame_width_list = []
- each_video_frame_height_list = []
+ def process_folder_full_of_videos(
+ self,
+ path_to_folder_of_videos_to_process: Union[Path, str],
+ output_data_folder_path: Union[str, Path],
+ save_annotated_videos: bool = True,
+ ):
+
+ path_to_folder_of_videos_to_process = Path(path_to_folder_of_videos_to_process)
+
+ logger.info(f"processing videos from: {path_to_folder_of_videos_to_process}")
mediapipe2d_single_camera_npy_arrays_list = []
for video_number, this_synchronized_video_file_path in enumerate(
- synchronized_videos_path.glob("*.mp4")
+ path_to_folder_of_videos_to_process.glob("*.mp4")
):
logger.info(
f"Running `mediapipe` skeleton detection on video: {str(this_synchronized_video_file_path)}"
@@ -190,6 +189,7 @@ class MediaPipeSkeletonDetector:
this_video_width = this_video_capture_object.get(cv2.CAP_PROP_FRAME_WIDTH)
this_video_height = this_video_capture_object.get(cv2.CAP_PROP_FRAME_HEIGHT)
+ this_video_framerate = this_video_capture_object.get(cv2.CAP_PROP_FPS)
this_video_mediapipe_results_list = []
this_video_annotated_images_list = []
@@ -206,9 +206,7 @@ class MediaPipeSkeletonDetector:
frame_number += 1
if frame_number % 5 == 0:
- print(
- f"frame {frame_number} out of {APP_STATE.number_of_frames_in_the_mocap_videos}"
- )
+ print(f"frame {frame_number}")
mediapipe2d_data_payload = self.detect_skeleton_in_image(
raw_image=image
@@ -224,11 +222,24 @@ class MediaPipeSkeletonDetector:
success, image = this_video_capture_object.read()
if save_annotated_videos:
- self.save_annotated_videos(
- this_video_annotated_images_list,
- this_synchronized_video_file_path.stem,
- this_video_width,
- this_video_height,
+ annotated_video_path = (
+ path_to_folder_of_videos_to_process.parent / "annotated_videos"
+ )
+ annotated_video_path.mkdir(exist_ok=True, parents=True)
+ annotated_video_name = (
+ this_synchronized_video_file_path.stem + "_mediapipe.mp4"
+ )
+ annotated_video_save_path = annotated_video_path / annotated_video_name
+
+ video_recorder = VideoRecorder()
+
+ logger.info(
+ f"Saving mediapipe annotated video to : {annotated_video_save_path}"
+ )
+ video_recorder.save_image_list_to_disk(
+ image_list=this_video_annotated_images_list,
+ path_to_save_video_file=annotated_video_save_path,
+ frames_per_second=this_video_framerate,
)
this_camera_mediapipe_2d_single_camera_npy_arrays = (
@@ -275,13 +286,19 @@ class MediaPipeSkeletonDetector:
this_cam_num, :, :, :
] = all_cameras_data2d_list[this_cam_num]
- self._save_mediapipe2d_data_to_npy(data2d_numCams_numFrames_numTrackedPts_XY)
- return data2d_numCams_numFrames_numTrackedPts_XY
+ mediapipe_data_2d_npy_path = self._save_mediapipe2d_data_to_npy(
+ data2d_numCams_numFrames_numTrackedPts_XY=data2d_numCams_numFrames_numTrackedPts_XY,
+ output_data_folder_path=Path(output_data_folder_path),
+ )
+ return str(mediapipe_data_2d_npy_path)
- def _save_mediapipe2d_data_to_npy(self, data2d_numCams_numFrames_numTrackedPts_XY):
- output_data_folder = Path(get_session_output_data_folder_path(self._session_id))
+ def _save_mediapipe2d_data_to_npy(
+ self,
+ data2d_numCams_numFrames_numTrackedPts_XY: np.ndarray,
+ output_data_folder_path: Union[str, Path],
+ ):
mediapipe_2dData_save_path = (
- output_data_folder
+ Path(output_data_folder_path)
/ "mediapipe_2dData_numCams_numFrames_numTrackedPoints_pixelXY.npy"
)
logger.info(f"saving: {mediapipe_2dData_save_path}")
@@ -289,31 +306,7 @@ class MediaPipeSkeletonDetector:
str(mediapipe_2dData_save_path), data2d_numCams_numFrames_numTrackedPts_XY
)
- def save_annotated_videos(
- self,
- annotated_images_list: List[np.ndarray],
- video_file_name: str,
- image_width: Union[int, float],
- image_height: Union[int, float],
- ):
-
- this_video_name = video_file_name + "_mediapipe.mp4"
-
- video_recorder = VideoRecorder(
- this_video_name,
- image_width,
- image_height,
- self._session_id,
- mediapipe_annotated_video_bool=True,
- )
-
- logger.info(f"Saving mediapipe annotated video: {this_video_name}")
- video_recorder.save_image_list_to_disk(
- annotated_images_list, frames_per_second=30
- )
- logger.info(
- f"mediapipe annotated video saved to: {video_recorder.path_to_save_video_file}"
- )
+ return mediapipe_2dData_save_path
def _annotate_image(self, image, mediapipe_results):
self._mp_drawing.draw_landmarks(
diff --git a/src/core_processor/show_cam_window.py b/src/core_processes/show_cam_window.py
similarity index 64%
rename from src/core_processor/show_cam_window.py
rename to src/core_processes/show_cam_window.py
index b89a97ec..82b6bd12 100644
--- a/src/core_processor/show_cam_window.py
+++ b/src/core_processes/show_cam_window.py
@@ -3,8 +3,8 @@ import logging
import cv2
import numpy as np
-from src.core_processor.timestamp_manager.timestamp_manager import TimestampManager
-from src.core_processor.utils.image_fps_writer import write_fps_to_image
+from src.core_processes.timestamp_manager.timestamp_manager import TimestampManager
+from src.core_processes.utils.image_fps_writer import write_fps_to_image
logger = logging.getLogger(__name__)
diff --git a/src/core_processor/timestamp_manager/timestamp_manager.py b/src/core_processes/timestamp_manager/timestamp_manager.py
similarity index 100%
rename from src/core_processor/timestamp_manager/timestamp_manager.py
rename to src/core_processes/timestamp_manager/timestamp_manager.py
diff --git a/src/core_processor/utils/image_fps_writer.py b/src/core_processes/utils/image_fps_writer.py
similarity index 100%
rename from src/core_processor/utils/image_fps_writer.py
rename to src/core_processes/utils/image_fps_writer.py
diff --git a/src/gui/main/state/__init__.py b/src/export_stuff/__init__.py
similarity index 100%
rename from src/gui/main/state/__init__.py
rename to src/export_stuff/__init__.py
diff --git a/src/gui/main/workers/__init__.py b/src/export_stuff/blender_stuff/__init__.py
similarity index 100%
rename from src/gui/main/workers/__init__.py
rename to src/export_stuff/blender_stuff/__init__.py
diff --git a/src/open_in_blender/alpha_freemocap_blender_megascript.py b/src/export_stuff/blender_stuff/alpha_freemocap_blender_megascript.py
similarity index 100%
rename from src/open_in_blender/alpha_freemocap_blender_megascript.py
rename to src/export_stuff/blender_stuff/alpha_freemocap_blender_megascript.py
diff --git a/src/open_in_blender/open_session_in_blender.py b/src/export_stuff/blender_stuff/create_blend_file_from_session_data.py
similarity index 61%
rename from src/open_in_blender/open_session_in_blender.py
rename to src/export_stuff/blender_stuff/create_blend_file_from_session_data.py
index eee14b77..28361024 100644
--- a/src/open_in_blender/open_session_in_blender.py
+++ b/src/export_stuff/blender_stuff/create_blend_file_from_session_data.py
@@ -1,22 +1,17 @@
-import os
-import sys
-from pathlib import Path
import subprocess
-from src.config.home_dir import get_session_folder_path, get_most_recent_session_id
-
-# blender_exe_path = r"C:\Users\jonma\Blender Foundation\stable\blender-3.1.0-windows-x64\blender.exe"
-blender_exe_path = r"C:\Users\jonma\Blender Foundation\Blender 3.1\blender.exe"
-
+from pathlib import Path
-def open_session_in_blender(session_id: str):
- create_session(session_id)
- blender_file_name = session_id + ".blend"
- blender_file_path = Path(get_session_folder_path(session_id)) / blender_file_name
- os.startfile(str(blender_file_path))
+from src.config.home_dir import get_session_folder_path
+blender_exe_path = (
+ r"C:\Users\jonma\Blender Foundation\stable\blender-3.1.0-windows-x64\blender.exe"
+)
+# blender_exe_path = r"C:\Users\jonma\Blender Foundation\Blender 3.1\blender.exe"
-def create_session(session_id: str, good_clean_frame_number: int = 0):
+def create_blend_file_from_session_data(
+ session_id: str, good_clean_frame_number: int = 0
+):
path_to_this_py_file = Path(__file__).parent.resolve()
freemocap_blender_megascript_path = (
path_to_this_py_file / "alpha_freemocap_blender_megascript.py"
@@ -50,7 +45,3 @@ def create_session(session_id: str, good_clean_frame_number: int = 0):
print("Blender returned an error:")
print(blender_process.stderr.read().decode())
print(f"done with blender stuff :D")
-
-
-if __name__ == "__main__":
- open_session_in_blender(get_most_recent_session_id())
diff --git a/src/export_stuff/blender_stuff/open_session_in_blender.py b/src/export_stuff/blender_stuff/open_session_in_blender.py
new file mode 100644
index 00000000..aa60e0e1
--- /dev/null
+++ b/src/export_stuff/blender_stuff/open_session_in_blender.py
@@ -0,0 +1,18 @@
+import os
+
+from pathlib import Path
+from src.config.home_dir import get_session_folder_path, get_most_recent_session_id
+from src.export_stuff.blender_stuff.create_blend_file_from_session_data import (
+ create_blend_file_from_session_data,
+)
+
+
+def open_session_in_blender(session_id: str):
+ create_blend_file_from_session_data(session_id)
+ blender_file_name = session_id + ".blend"
+ blender_file_path = Path(get_session_folder_path(session_id)) / blender_file_name
+ os.startfile(str(blender_file_path))
+
+
+if __name__ == "__main__":
+ open_session_in_blender(get_most_recent_session_id())
diff --git a/src/open_in_blender/__init__.py b/src/gui/icis_conference_main/__init__.py
similarity index 100%
rename from src/open_in_blender/__init__.py
rename to src/gui/icis_conference_main/__init__.py
diff --git a/src/gui/icis_conference_main/icis_conference_app.py b/src/gui/icis_conference_main/icis_conference_app.py
new file mode 100644
index 00000000..26ec678c
--- /dev/null
+++ b/src/gui/icis_conference_main/icis_conference_app.py
@@ -0,0 +1,11 @@
+from pyqtgraph import mkQApp
+
+APP = None
+
+
+def get_qt_app():
+ global APP
+ if APP is None:
+ APP = mkQApp()
+
+ return APP
diff --git a/src/gui/icis_conference_main/icis_conference_main.py b/src/gui/icis_conference_main/icis_conference_main.py
new file mode 100644
index 00000000..86c03df6
--- /dev/null
+++ b/src/gui/icis_conference_main/icis_conference_main.py
@@ -0,0 +1,31 @@
+import signal
+import sys
+
+from PyQt6.QtCore import QTimer
+from PyQt6.QtWidgets import QApplication
+
+# from src.api.routes.session.session_router import visualize_session_offline
+from src.gui.icis_conference_main.icis_conference_app import get_qt_app
+from src.gui.icis_conference_main.layout.ICIS_conference_main_window import (
+ ICISConferenceMainWindow,
+)
+from src.gui.icis_conference_main.layout.slop_main_window import SlopMainWindow
+
+
+def sigint_handler(*args):
+ """Handler for the SIGINT signal."""
+ QApplication.quit()
+
+
+if __name__ == "__main__":
+ signal.signal(signal.SIGINT, sigint_handler)
+ app = get_qt_app()
+ timer = QTimer()
+ timer.start(500)
+ timer.timeout.connect(lambda: None) # Let the interpreter run each 500 ms.
+ win = ICISConferenceMainWindow()
+ # win = SlopMainWindow()
+ win.show()
+ sys.exit(app.exec())
+ # app.exec()
+ # visualize_session_offline()
diff --git a/src/gui/main/layout/main_window.py b/src/gui/icis_conference_main/layout/ICIS_conference_main_window.py
similarity index 67%
rename from src/gui/main/layout/main_window.py
rename to src/gui/icis_conference_main/layout/ICIS_conference_main_window.py
index 332939ef..fc532724 100644
--- a/src/gui/main/layout/main_window.py
+++ b/src/gui/icis_conference_main/layout/ICIS_conference_main_window.py
@@ -2,18 +2,27 @@ from PyQt6.QtCore import Qt
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import QMainWindow, QMenuBar, QVBoxLayout, QWidget, QCheckBox
-from src.gui.main.app import get_qt_app
-from src.gui.main.qt_utils.clear_layout import clearLayout
-from src.gui.main.state.app_state import APP_STATE
-from src.gui.main.workflows.calibration_instructions import CalibrationInstructions
-from src.gui.main.workflows.camera_configuration import CameraConfiguration
-from src.gui.main.workflows.new_recording_session import NewRecordingSession
-from src.gui.main.workflows.record_videos import RecordVideos
-from src.gui.main.workflows.show_cams_charuco import ShowCamsCharuco
-from src.gui.main.workflows.welcome import Welcome
-
-
-class MainWindow(QMainWindow):
+from src.gui.icis_conference_main.icis_conference_app import get_qt_app
+from src.gui.icis_conference_main.qt_utils.clear_layout import clearLayout
+from src.gui.icis_conference_main.qt_widgets.jupyter_console_widget import (
+ JupyterConsoleWidget,
+)
+from src.gui.icis_conference_main.state.app_state import APP_STATE
+from src.gui.icis_conference_main.workflows.calibration_instructions import (
+ CalibrationInstructions,
+)
+from src.gui.icis_conference_main.workflows.camera_configuration import (
+ CameraConfiguration,
+)
+from src.gui.icis_conference_main.workflows.new_recording_session import (
+ NewRecordingSession,
+)
+from src.gui.icis_conference_main.workflows.record_videos import RecordVideos
+from src.gui.icis_conference_main.workflows.show_cams_charuco import ShowCamsCharuco
+from src.gui.icis_conference_main.workflows.welcome import Welcome
+
+
+class ICISConferenceMainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("freemocap")
@@ -21,13 +30,14 @@ class MainWindow(QMainWindow):
self._create_menu_bar()
self.statusBar()
self._main_layout = self._create_basic_layout()
-
+ self._jupyter_console_widget = self._add_jupyter_console_widget()
self._show_welcome_screen()
def _create_basic_layout(self):
main_layout = QVBoxLayout()
widget = QWidget()
widget.setLayout(main_layout)
+
self.setCentralWidget(widget)
return main_layout
@@ -63,6 +73,12 @@ class MainWindow(QMainWindow):
action.triggered.connect(self._show_recording_session_screen)
return action
+ def _add_jupyter_console_widget(self):
+ # create jupyter console widget
+ jupyter_console_widget = JupyterConsoleWidget()
+ get_qt_app().aboutToQuit.connect(jupyter_console_widget.shutdown_kernel)
+ return jupyter_console_widget
+
# more top-level screens go here
# this will be refactored later
def _show_welcome_screen(self):
@@ -85,23 +101,24 @@ class MainWindow(QMainWindow):
self._main_layout.addWidget(screen)
self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
# screen.config_accepted.clicked.connect(self._show_calibration_instructions_screen)
- if APP_STATE.use_previous_calibration:
+ if APP_STATE.use_previous_calibration_box_is_checked:
screen.config_accepted.clicked.connect(self._show_record_videos_screen)
else:
screen.config_accepted.clicked.connect(self._show_calibration_screen)
- def _show_calibration_instructions_screen(self):
- clearLayout(self._main_layout)
- screen = CalibrationInstructions()
- self._main_layout.addWidget(screen)
- self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
- screen.continue_button.clicked.connect(self._show_calibration_screen)
+ # def _show_calibration_instructions_screen(self):
+ # clear_layout(self._main_layout)
+ # screen = CalibrationInstructions()
+ # self._main_layout.addWidget(screen)
+ # self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+ # screen.continue_button.clicked.connect(self._show_calibration_screen)
def _show_calibration_screen(self):
clearLayout(self._main_layout)
screen = ShowCamsCharuco()
self._main_layout.addWidget(screen)
self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+ self._main_layout.addWidget(self._jupyter_console_widget)
screen.continue_button.clicked.connect(self._show_record_videos_screen)
def _show_record_videos_screen(self):
diff --git a/src/gui/icis_conference_main/layout/slop_main_window.py b/src/gui/icis_conference_main/layout/slop_main_window.py
new file mode 100644
index 00000000..6fb49d51
--- /dev/null
+++ b/src/gui/icis_conference_main/layout/slop_main_window.py
@@ -0,0 +1,192 @@
+from PyQt6.QtCore import Qt
+from PyQt6.QtGui import QAction
+from PyQt6.QtWidgets import (
+ QMainWindow,
+ QMenuBar,
+ QWidget,
+ QHBoxLayout,
+ QGridLayout,
+ QVBoxLayout,
+ QLabel,
+ QFrame,
+ QSplitter,
+)
+
+from src.gui.icis_conference_main.icis_conference_app import get_qt_app
+from src.gui.icis_conference_main.qt_utils.clear_layout import clearLayout
+from src.gui.icis_conference_main.qt_widgets.jupyter_console_widget import (
+ JupyterConsoleWidget,
+)
+from src.gui.icis_conference_main.state.app_state import APP_STATE
+from src.gui.icis_conference_main.workflows.calibration_instructions import (
+ CalibrationInstructions,
+)
+from src.gui.icis_conference_main.workflows.camera_configuration import (
+ CameraConfiguration,
+)
+from src.gui.icis_conference_main.workflows.new_recording_session import (
+ NewRecordingSession,
+)
+from src.gui.icis_conference_main.workflows.record_videos import RecordVideos
+from src.gui.icis_conference_main.workflows.show_cams_charuco import ShowCamsCharuco
+from src.gui.icis_conference_main.workflows.welcome import Welcome
+
+
+class SlopMainWindow(QMainWindow):
+ def __init__(self):
+ super().__init__()
+ self.setWindowTitle("freemocap")
+ self._main_window_width = int(1920 * 0.8)
+ self._main_window_height = int(1080 * 0.8)
+ self.setGeometry(0, 0, self._main_window_width, self._main_window_height)
+ self._create_menu_bar()
+ self.statusBar()
+ self._main_layout = self._create_basic_layout()
+
+ self._control_panel_layout = self._create_control_panel_layout()
+ self._camera_view_panel_layout = self._create_camera_view_panel_layout()
+
+ self._jupyter_console_widget = self._create_jupyter_console_widget()
+ self._console_panel_layout = self._create_console_panel_layout(
+ self._jupyter_console_widget
+ )
+
+ self._jupyter_console_widget.print("Hello there!")
+ self._show_welcome_view()
+
+ def _create_basic_layout(self):
+ main_layout = QHBoxLayout()
+ widget = QWidget()
+ widget.setLayout(main_layout)
+
+ self.setCentralWidget(widget)
+ return main_layout
+
+ def _create_control_panel_layout(self):
+ control_panel_frame = QFrame()
+ control_panel_frame.setFixedWidth(self._main_window_width * 0.2)
+ control_panel_frame.setFrameShape(QFrame.Shape.StyledPanel)
+ control_panel_layout = QVBoxLayout()
+ control_panel_frame.setLayout(control_panel_layout)
+ splitter = QSplitter(Qt.Orientation.Vertical)
+ splitter.addWidget((control_panel_frame))
+ self._main_layout.addWidget(splitter)
+ return control_panel_layout
+
+ def _create_camera_view_panel_layout(self):
+ camera_view_panel_frame = QFrame()
+ camera_view_panel_frame.setFixedWidth(self._main_window_width * 0.4)
+ camera_view_panel_frame.setFrameShape(QFrame.Shape.StyledPanel)
+ camera_view_panel_layout = QVBoxLayout()
+ camera_view_panel_frame.setLayout(camera_view_panel_layout)
+ splitter = QSplitter(Qt.Orientation.Vertical)
+ splitter.addWidget((camera_view_panel_frame))
+ self._main_layout.addWidget(splitter)
+ return camera_view_panel_layout
+
+ def _create_console_panel_layout(self, jupyter_console_widget):
+ console_panel_frame = QFrame()
+ console_panel_frame.setFixedWidth(self._main_window_width * 0.4)
+ console_panel_frame.setFrameShape(QFrame.Shape.StyledPanel)
+ console_panel_layout = QVBoxLayout()
+ console_panel_layout.addWidget(jupyter_console_widget)
+ console_panel_frame.setLayout(console_panel_layout)
+ splitter = QSplitter(Qt.Orientation.Vertical)
+ splitter.addWidget((console_panel_frame))
+ self._main_layout.addWidget(splitter)
+ return console_panel_layout
+
+ def _create_menu_bar(self):
+ menubar = self.menuBar()
+ menubar.setNativeMenuBar(False)
+ self._add_file_menu(menubar)
+
+ def _add_file_menu(self, menubar: QMenuBar):
+ exit_action = self._create_exit_action()
+ record_action = self._create_new_recording_session_action()
+ file_menu = menubar.addMenu("&File")
+ file_menu.addAction(record_action)
+ file_menu.addAction(exit_action)
+
+ def _create_exit_action(self):
+ # src/freemocap_qt_gui/conference/assets/new_recording_session.png
+ action = QAction("&Quit", self)
+ action.setShortcut("Ctrl+Q")
+ action.setStatusTip("Exit application")
+
+ # On triggered, quit the application
+ action.triggered.connect(get_qt_app().quit)
+
+ return action
+
+ def _create_new_recording_session_action(self):
+ action = QAction("&New Recording Session", self)
+ action.setShortcut("Ctrl+N")
+ action.setStatusTip("Begin a new recording session")
+
+ # On triggered, quit the application
+ # action.triggered.connect(self._show_welcome_view)
+ action.triggered.connect(self._show_cam_config_screen)
+ return action
+
+ def _create_jupyter_console_widget(self):
+ # create jupyter console widget
+ jupyter_console_widget = JupyterConsoleWidget()
+ get_qt_app().aboutToQuit.connect(jupyter_console_widget.shutdown_kernel)
+
+ return jupyter_console_widget
+
+ # # more top-level screens go here
+ # # this will be refactored later
+ # def _show_welcome_screen(self):
+ # clear_layout(self._main_layout)
+ # screen = Welcome()
+ # self._main_layout.addWidget(screen)
+ # self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+ # screen.new_session.clicked.connect(self._show_welcome_view)
+
+ def _show_welcome_view(self):
+ clearLayout(self._control_panel_layout)
+ screen = NewRecordingSession()
+ self._control_panel_layout.addWidget(screen)
+ # self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+ # screen.start_new_session_button.clicked.connect(self._show_cam_config_screen)
+ screen.submit.clicked.connect(self._show_cam_config_screen)
+
+ def _show_cam_config_screen(self):
+ clearLayout(self._camera_view_panel_layout)
+ screen = CameraConfiguration()
+ self._camera_view_panel_layout.addWidget(screen)
+ # self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+ # screen.config_accepted.clicked.connect(self._show_calibration_instructions_screen)
+ if APP_STATE.use_previous_calibration_box_is_checked:
+ screen.config_accepted.clicked.connect(self._show_record_videos_screen)
+ else:
+ screen.config_accepted.clicked.connect(self._show_calibration_screen)
+
+ # def _show_calibration_instructions_screen(self):
+ # clear_layout(self._main_layout)
+ # screen = CalibrationInstructions()
+ # self._main_layout.addWidget(screen)
+ # self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+ # screen.continue_button.clicked.connect(self._show_calibration_screen)
+
+ def _show_calibration_screen(self):
+ clearLayout(self._main_layout)
+ screen = ShowCamsCharuco()
+ self._main_layout.addWidget(screen)
+ self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
+ self._main_layout.addWidget(self._jupyter_console_widget)
+ screen.continue_button.clicked.connect(self._show_record_videos_screen)
+
+ def _show_record_videos_screen(self):
+ clearLayout(self._camera_view_panel_layout)
+ self._jupyter_console_widget.print(
+ f"Session started with id: {APP_STATE.session_id}"
+ )
+ screen = RecordVideos()
+ self._camera_view_panel_layout.addWidget(screen)
+
+ # self._main_layout.addWidget(self._jupyter_console_widget)
+
+ # self._main_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
diff --git a/src/gui/icis_conference_main/qt_utils/clear_layout.py b/src/gui/icis_conference_main/qt_utils/clear_layout.py
new file mode 100644
index 00000000..f7c1ba70
--- /dev/null
+++ b/src/gui/icis_conference_main/qt_utils/clear_layout.py
@@ -0,0 +1,5 @@
+def clearLayout(layout):
+ while layout.count():
+ child = layout.takeAt(0)
+ if child.widget():
+ child.widget().deleteLater()
diff --git a/src/gui/icis_conference_main/qt_utils/set_font_size.py b/src/gui/icis_conference_main/qt_utils/set_font_size.py
new file mode 100644
index 00000000..bcd5e4e9
--- /dev/null
+++ b/src/gui/icis_conference_main/qt_utils/set_font_size.py
@@ -0,0 +1,7 @@
+from PyQt6.QtWidgets import QLabel
+
+
+def set_font_size(label_widget: QLabel, size: int):
+ font = label_widget.font()
+ font.setPointSize(size)
+ label_widget.setFont(font)
diff --git a/src/gui/icis_conference_main/qt_widgets/jupyter_console_widget.py b/src/gui/icis_conference_main/qt_widgets/jupyter_console_widget.py
new file mode 100644
index 00000000..24331fd9
--- /dev/null
+++ b/src/gui/icis_conference_main/qt_widgets/jupyter_console_widget.py
@@ -0,0 +1,107 @@
+"""
+This example show how to create a Rich Jupyter Widget, and places it in a MainWindow alongside a PlotWidget.
+
+The widgets are implemented as `Docks` so they may be moved around within the Main Window
+
+The `__main__` function shows an example that inputs the commands to plot simple `sine` and cosine` waves, equivalent to creating such plots by entering the commands manually in the console
+
+Also shows the use of `whos`, which returns a list of the variables defined within the `ipython` kernel
+
+This method for creating a Jupyter console is based on the example(s) here:
+https://github.com/jupyter/qtconsole/tree/b4e08f763ef1334d3560d8dac1d7f9095859545a/examples
+especially-
+https://github.com/jupyter/qtconsole/blob/b4e08f763ef1334d3560d8dac1d7f9095859545a/examples/embed_qtconsole.py#L19
+
+"""
+
+
+import numpy as np
+import pyqtgraph as pg
+from pyqtgraph.Qt import QtWidgets
+from pyqtgraph.dockarea.Dock import Dock
+from pyqtgraph.dockarea.DockArea import DockArea
+
+try:
+ from qtconsole import inprocess
+except:
+ print(
+ "The example in `jupyter_console_example.py` requires `qtconsole` to run. Install with `pip install qtconsole` or equivalent."
+ )
+
+
+class JupyterConsoleWidget(inprocess.QtInProcessRichJupyterWidget):
+ def __init__(self, dark_mode: bool = True):
+ super().__init__()
+
+ self.kernel_manager = inprocess.QtInProcessKernelManager()
+ self.kernel_manager.start_kernel()
+ self.kernel_client = self.kernel_manager.client()
+ self.kernel_client.start_channels()
+ self._import_stuff()
+ self.execute("%whos")
+ if dark_mode:
+ self.set_default_style("linux")
+
+ def _import_stuff(self):
+ self.execute("import numpy as np")
+ self.execute("import matplotlib.pyplot as plt")
+
+ def print(self, message: str):
+ self.execute(f"print('{message}')")
+
+ def shutdown_kernel(self):
+ self.kernel_client.stop_channels()
+ self.kernel_manager.shutdown_kernel()
+
+
+class MainWindow(QtWidgets.QMainWindow):
+ def __init__(self, dark_mode=True):
+ super().__init__()
+ central_dock_area = DockArea()
+
+ # create plot widget (and dock)
+ self.plot_widget = pg.PlotWidget()
+ plot_dock = Dock(name="Plot Widget Dock", closable=True)
+ plot_dock.addWidget(self.plot_widget)
+ central_dock_area.addDock(plot_dock)
+
+ # create jupyter console widget (and dock)
+ self.jupyter_console_widget = JupyterConsoleWidget()
+ jupyter_console_dock = Dock("Jupyter Console Dock")
+ jupyter_console_dock.addWidget(self.jupyter_console_widget)
+ central_dock_area.addDock(jupyter_console_dock)
+ self.setCentralWidget(central_dock_area)
+
+ app = QtWidgets.QApplication.instance()
+ app.aboutToQuit.connect(self.jupyter_console_widget.shutdown_kernel)
+
+ kernel = self.jupyter_console_widget.kernel_manager.kernel
+ kernel.shell.push_variables(dict(np=np, pw=self.plot_widget))
+
+ # set dark mode
+ if dark_mode:
+ # Set Dark bg color via this relatively roundabout method
+ self.jupyter_console_widget.set_default_style("linux")
+
+
+if __name__ == "__main__":
+ pg.mkQApp()
+ main = MainWindow(dark_mode=True)
+ main.show()
+ main.jupyter_console_widget.execute('print("hello world :D ")')
+
+ # plot a sine/cosine waves by printing to console
+ # this is equivalent to typing the commands into the console manually
+ main.jupyter_console_widget.execute("x = np.arange(0, 3 * np.pi, .1)")
+ main.jupyter_console_widget.execute("pw.plotItem.plot(np.sin(x), pen='r')")
+ main.jupyter_console_widget.execute(
+ "pw.plotItem.plot(np.cos(x),\
+ pen='cyan',\
+ symbol='o',\
+ symbolPen='m',\
+ symbolBrush=(0,0,255))"
+ )
+ main.jupyter_console_widget.execute("whos")
+ main.jupyter_console_widget.execute("")
+
+ pg.exec()
diff --git a/src/gui/main/shared_widgets/page_title.py b/src/gui/icis_conference_main/shared_widgets/page_title.py
similarity index 80%
rename from src/gui/main/shared_widgets/page_title.py
rename to src/gui/icis_conference_main/shared_widgets/page_title.py
index 435cc04a..93183b5e 100644
--- a/src/gui/main/shared_widgets/page_title.py
+++ b/src/gui/icis_conference_main/shared_widgets/page_title.py
@@ -1,7 +1,7 @@
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QLabel
-from src.gui.main.qt_utils.set_font_size import set_font_size
+from src.gui.icis_conference_main.qt_utils.set_font_size import set_font_size
class PageTitle(QLabel):
diff --git a/src/gui/main/shared_widgets/primary_button.py b/src/gui/icis_conference_main/shared_widgets/primary_button.py
similarity index 100%
rename from src/gui/main/shared_widgets/primary_button.py
rename to src/gui/icis_conference_main/shared_widgets/primary_button.py
diff --git a/src/gui/icis_conference_main/state/__init__.py b/src/gui/icis_conference_main/state/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/gui/main/state/app_state.py b/src/gui/icis_conference_main/state/app_state.py
similarity index 100%
rename from src/gui/main/state/app_state.py
rename to src/gui/icis_conference_main/state/app_state.py
diff --git a/src/gui/icis_conference_main/workers/__init__.py b/src/gui/icis_conference_main/workers/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/gui/main/workers/cam_charuco_frame_worker.py b/src/gui/icis_conference_main/workers/cam_charuco_frame_worker.py
similarity index 93%
rename from src/gui/main/workers/cam_charuco_frame_worker.py
rename to src/gui/icis_conference_main/workers/cam_charuco_frame_worker.py
index da0dc0b3..07f1d9d8 100644
--- a/src/gui/main/workers/cam_charuco_frame_worker.py
+++ b/src/gui/icis_conference_main/workers/cam_charuco_frame_worker.py
@@ -4,7 +4,7 @@ from PyQt6.QtGui import QImage
from src.cameras.capture.opencv_camera.opencv_camera import OpenCVCamera
from src.config.webcam_config import WebcamConfig
-from src.gui.main.state.app_state import APP_STATE
+from src.gui.icis_conference_main.state.app_state import APP_STATE
from src.pipelines.calibration_pipeline.charuco_board_detection.charuco_board_detector import (
CharucoBoardDetector,
)
@@ -55,7 +55,9 @@ class CamCharucoFrameWorker(QThread):
print("saving frame :D")
cam.video_recorder.append_frame_payload_to_list(payload)
- charuco_payload = self._board_thingy.detect_charuco_board(payload)
+ charuco_payload = (
+ self._board_thingy.detect_charuco_board_in_frame_payload(payload)
+ )
image_to_display = charuco_payload.annotated_image
image_to_display = cv2.flip(image_to_display, 1)
image_to_display = cv2.cvtColor(image_to_display, cv2.COLOR_BGR2RGB)
diff --git a/src/gui/main/workers/cam_detection_thread.py b/src/gui/icis_conference_main/workers/cam_detection_thread.py
similarity index 100%
rename from src/gui/main/workers/cam_detection_thread.py
rename to src/gui/icis_conference_main/workers/cam_detection_thread.py
diff --git a/src/gui/icis_conference_main/workers/cam_frame_worker.py b/src/gui/icis_conference_main/workers/cam_frame_worker.py
new file mode 100644
index 00000000..60ec9857
--- /dev/null
+++ b/src/gui/icis_conference_main/workers/cam_frame_worker.py
@@ -0,0 +1,45 @@
+import cv2
+from PyQt6.QtCore import QThread, Qt, pyqtSignal
+from PyQt6.QtGui import QImage
+
+from src.cameras.capture.opencv_camera.opencv_camera import OpenCVCamera
+from src.config.webcam_config import WebcamConfig
+
+
+class CamFrameWorker(QThread):
+ ImageUpdate = pyqtSignal(QImage)
+
+ def __init__(self, cam_id=None):
+ super().__init__()
+ self._cam_id = cam_id
+
+ def run(self):
+ cam = OpenCVCamera(WebcamConfig(webcam_id=self._cam_id))
+ cam.connect()
+ cam.start_frame_capture_thread()
+ self._cam = cam
+ try:
+ while cam.is_capturing_frames:
+ if not cam.new_frame_ready:
+ continue
+ payload = cam.latest_frame
+
+ image = cv2.flip(payload.image, 1)
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+ converted_frame = QImage(
+ image.data,
+ image.shape[1],
+ image.shape[0],
+ QImage.Format.Format_RGB888,
+ )
+ converted_frame = converted_frame.scaled(
+ 640, 480, Qt.AspectRatioMode.KeepAspectRatio
+ )
+ self.ImageUpdate.emit(converted_frame)
+ finally:
+ print("Closing the camera")
+ self._cam.close()
+
+ def quit(self):
+ self._cam.close()
+ super().quit()
diff --git a/src/gui/main/workflows/available_camera.py b/src/gui/icis_conference_main/workflows/available_camera.py
similarity index 100%
rename from src/gui/main/workflows/available_camera.py
rename to src/gui/icis_conference_main/workflows/available_camera.py
diff --git a/src/gui/main/workflows/available_cameras_list.py b/src/gui/icis_conference_main/workflows/available_cameras_list.py
similarity index 92%
rename from src/gui/main/workflows/available_cameras_list.py
rename to src/gui/icis_conference_main/workflows/available_cameras_list.py
index e4350ea6..378f3eda 100644
--- a/src/gui/main/workflows/available_cameras_list.py
+++ b/src/gui/icis_conference_main/workflows/available_cameras_list.py
@@ -4,9 +4,9 @@ from PyQt6.QtCore import Qt, pyqtSignal
from PyQt6.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout, QWidget
from src.cameras.detection.models import FoundCamerasResponse
-from src.gui.main.qt_utils.clear_layout import clearLayout
-from src.gui.main.workers.cam_detection_thread import CamDetectionWorker
-from src.gui.main.workflows.available_camera import AvailableCamera
+from src.gui.icis_conference_main.qt_utils.clear_layout import clearLayout
+from src.gui.icis_conference_main.workers.cam_detection_thread import CamDetectionWorker
+from src.gui.icis_conference_main.workflows.available_camera import AvailableCamera
class AvailableCamerasList(QWidget):
diff --git a/src/gui/main/workflows/calibration_instructions.py b/src/gui/icis_conference_main/workflows/calibration_instructions.py
similarity index 90%
rename from src/gui/main/workflows/calibration_instructions.py
rename to src/gui/icis_conference_main/workflows/calibration_instructions.py
index 17000c5c..c47b2933 100644
--- a/src/gui/main/workflows/calibration_instructions.py
+++ b/src/gui/icis_conference_main/workflows/calibration_instructions.py
@@ -1,7 +1,7 @@
from PyQt6.QtWidgets import QHBoxLayout, QLabel, QVBoxLayout, QWidget
-from src.gui.main.shared_widgets.page_title import PageTitle
-from src.gui.main.shared_widgets.primary_button import PrimaryButton
+from src.gui.icis_conference_main.shared_widgets.page_title import PageTitle
+from src.gui.icis_conference_main.shared_widgets.primary_button import PrimaryButton
class CalibrationInstructions(QWidget):
diff --git a/src/gui/main/workflows/camera_configuration.py b/src/gui/icis_conference_main/workflows/camera_configuration.py
similarity index 88%
rename from src/gui/main/workflows/camera_configuration.py
rename to src/gui/icis_conference_main/workflows/camera_configuration.py
index 0fa4bb44..b1cc4198 100644
--- a/src/gui/main/workflows/camera_configuration.py
+++ b/src/gui/icis_conference_main/workflows/camera_configuration.py
@@ -3,15 +3,17 @@ import time
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QHBoxLayout, QLabel, QPushButton, QVBoxLayout, QWidget
-from src.gui.main.shared_widgets.page_title import PageTitle
-from src.gui.main.shared_widgets.primary_button import (
+from src.gui.icis_conference_main.shared_widgets.page_title import PageTitle
+from src.gui.icis_conference_main.shared_widgets.primary_button import (
PrimaryButton,
not_active_primary_button_style_sheet,
active_primary_button_style_sheet,
)
-from src.gui.main.state.app_state import APP_STATE
-from src.gui.main.workers.cam_frame_worker import CamFrameWorker
-from src.gui.main.workflows.available_cameras_list import AvailableCamerasList
+from src.gui.icis_conference_main.state.app_state import APP_STATE
+from src.gui.icis_conference_main.workers.cam_frame_worker import CamFrameWorker
+from src.gui.icis_conference_main.workflows.available_cameras_list import (
+ AvailableCamerasList,
+)
class CameraConfiguration(QWidget):
diff --git a/src/gui/main/workflows/new_recording_session.py b/src/gui/icis_conference_main/workflows/new_recording_session.py
similarity index 79%
rename from src/gui/main/workflows/new_recording_session.py
rename to src/gui/icis_conference_main/workflows/new_recording_session.py
index a6f09527..b78ccf04 100644
--- a/src/gui/main/workflows/new_recording_session.py
+++ b/src/gui/icis_conference_main/workflows/new_recording_session.py
@@ -8,10 +8,10 @@ from PyQt6.QtWidgets import (
QCheckBox,
)
-from src.config.home_dir import create_session_id
-from src.gui.main.shared_widgets.page_title import PageTitle
-from src.gui.main.shared_widgets.primary_button import PrimaryButton
-from src.gui.main.state.app_state import APP_STATE
+from src.config.home_dir import create_default_session_id
+from src.gui.icis_conference_main.shared_widgets.page_title import PageTitle
+from src.gui.icis_conference_main.shared_widgets.primary_button import PrimaryButton
+from src.gui.icis_conference_main.state.app_state import APP_STATE
class NewRecordingSession(QWidget):
@@ -34,10 +34,8 @@ class NewRecordingSession(QWidget):
session_id_text_layout.addWidget(self._create_session_input())
container.addLayout(session_id_text_layout)
-
- container.addLayout(self._create_submit_button_layout())
-
container.addWidget(self._use_previous_calibration_checkbox)
+ container.addLayout(self._create_submit_button_layout())
self.setLayout(container)
@@ -54,12 +52,14 @@ class NewRecordingSession(QWidget):
return previous_calibration_checkbox
def _create_record_sesion_title(self):
- session_title = PageTitle("Name Your Recording Session")
+ session_title = PageTitle(
+ "welcome \n to \n freemocap! \n \U00002728 \U0001F480 \U00002728 "
+ )
return session_title
def _create_session_input(self):
session_text_input = QLineEdit()
- session_text_input.setText(create_session_id())
+ session_text_input.setText(create_default_session_id())
return session_text_input
def _create_submit_button_layout(self):
@@ -72,6 +72,6 @@ class NewRecordingSession(QWidget):
APP_STATE.session_id = self._session_input.text()
def _use_previous_calibration_changed(self):
- APP_STATE.use_previous_calibration = (
+ APP_STATE.use_previous_calibration_box_is_checked = (
self._use_previous_calibration_checkbox.isChecked()
)
diff --git a/src/gui/main/workflows/record_instructions.py b/src/gui/icis_conference_main/workflows/record_instructions.py
similarity index 93%
rename from src/gui/main/workflows/record_instructions.py
rename to src/gui/icis_conference_main/workflows/record_instructions.py
index 80d3b77f..9344a740 100644
--- a/src/gui/main/workflows/record_instructions.py
+++ b/src/gui/icis_conference_main/workflows/record_instructions.py
@@ -1,6 +1,6 @@
from PyQt6.QtWidgets import QHBoxLayout, QLabel, QVBoxLayout, QWidget
-from src.gui.main.shared_widgets.primary_button import PrimaryButton
+from src.gui.icis_conference_main.shared_widgets.primary_button import PrimaryButton
class RecordInstructions(QWidget):
diff --git a/src/gui/main/workflows/record_videos.py b/src/gui/icis_conference_main/workflows/record_videos.py
similarity index 94%
rename from src/gui/main/workflows/record_videos.py
rename to src/gui/icis_conference_main/workflows/record_videos.py
index ec9e2464..070fdc4c 100644
--- a/src/gui/main/workflows/record_videos.py
+++ b/src/gui/icis_conference_main/workflows/record_videos.py
@@ -8,12 +8,14 @@ from PyQt6.QtWidgets import (
)
from src.cameras.save_synchronized_videos import save_synchronized_videos
-from src.core_processor.mediapipe_skeleton_detector.mediapipe_skeleton_detector import (
+from src.core_processes.mediapipe_2d_skeleton_detector.mediapipe_skeleton_detector import (
MediaPipeSkeletonDetector,
)
-from src.gui.main.state.app_state import APP_STATE
-from src.gui.main.workflows.single_camera import SingleCamera
-from src.open_in_blender.open_session_in_blender import open_session_in_blender
+from src.gui.icis_conference_main.state.app_state import APP_STATE
+from src.gui.icis_conference_main.workflows.single_camera import SingleCamera
+from src.export_stuff.blender_stuff.open_session_in_blender import (
+ open_session_in_blender,
+)
from src.pipelines.calibration_pipeline.calibration_pipeline_orchestrator import (
CalibrationPipelineOrchestrator,
)
@@ -146,7 +148,7 @@ class RecordVideos(QWidget):
session_id=APP_STATE.session_id
)
- if APP_STATE.use_previous_calibration:
+ if APP_STATE.use_previous_calibration_box_is_checked:
session_orchestrator.anipose_camera_calibration_object = (
CalibrationPipelineOrchestrator().load_most_recent_calibration()
)
diff --git a/src/gui/main/workflows/show_cams_charuco.py b/src/gui/icis_conference_main/workflows/show_cams_charuco.py
similarity index 95%
rename from src/gui/main/workflows/show_cams_charuco.py
rename to src/gui/icis_conference_main/workflows/show_cams_charuco.py
index ff5100ae..25c3390e 100644
--- a/src/gui/main/workflows/show_cams_charuco.py
+++ b/src/gui/icis_conference_main/workflows/show_cams_charuco.py
@@ -8,8 +8,8 @@ from PyQt6.QtWidgets import (
)
from src.cameras.save_synchronized_videos import save_synchronized_videos
-from src.gui.main.state.app_state import APP_STATE
-from src.gui.main.workflows.single_camera import SingleCamera
+from src.gui.icis_conference_main.state.app_state import APP_STATE
+from src.gui.icis_conference_main.workflows.single_camera import SingleCamera
from src.pipelines.calibration_pipeline.calibration_pipeline_orchestrator import (
CalibrationPipelineOrchestrator,
@@ -87,7 +87,7 @@ class ShowCamsCharuco(QWidget):
self._continue_button.setEnabled(
self._use_previous_calibration_checkbox.isChecked()
)
- APP_STATE.use_previous_calibration = (
+ APP_STATE.use_previous_calibration_box_is_checked = (
self._use_previous_calibration_checkbox.isChecked()
)
diff --git a/src/gui/main/workflows/single_camera.py b/src/gui/icis_conference_main/workflows/single_camera.py
similarity index 90%
rename from src/gui/main/workflows/single_camera.py
rename to src/gui/icis_conference_main/workflows/single_camera.py
index 20958bdc..624c2095 100644
--- a/src/gui/main/workflows/single_camera.py
+++ b/src/gui/icis_conference_main/workflows/single_camera.py
@@ -4,8 +4,10 @@ from PyQt6.QtCore import pyqtSignal
from PyQt6.QtGui import QPixmap
from PyQt6.QtWidgets import QHBoxLayout, QLabel, QWidget
-from src.gui.main.workers.cam_charuco_frame_worker import CamCharucoFrameWorker
-from src.gui.main.workers.cam_frame_worker import CamFrameWorker
+from src.gui.icis_conference_main.workers.cam_charuco_frame_worker import (
+ CamCharucoFrameWorker,
+)
+from src.gui.icis_conference_main.workers.cam_frame_worker import CamFrameWorker
class WorkerType(enum.Enum):
diff --git a/src/gui/main/workflows/visualize_session.py b/src/gui/icis_conference_main/workflows/visualize_session.py
similarity index 100%
rename from src/gui/main/workflows/visualize_session.py
rename to src/gui/icis_conference_main/workflows/visualize_session.py
diff --git a/src/gui/main/workflows/welcome.py b/src/gui/icis_conference_main/workflows/welcome.py
similarity index 89%
rename from src/gui/main/workflows/welcome.py
rename to src/gui/icis_conference_main/workflows/welcome.py
index 1c103250..3958655f 100644
--- a/src/gui/main/workflows/welcome.py
+++ b/src/gui/icis_conference_main/workflows/welcome.py
@@ -9,8 +9,8 @@ from PyQt6.QtWidgets import (
QCheckBox,
)
-from src.gui.main.qt_utils.set_font_size import set_font_size
-from src.gui.main.shared_widgets.primary_button import PrimaryButton
+from src.gui.icis_conference_main.qt_utils.set_font_size import set_font_size
+from src.gui.icis_conference_main.shared_widgets.primary_button import PrimaryButton
class Welcome(QWidget):
diff --git a/src/gui/main/app_state/app_state.py b/src/gui/main/app_state/app_state.py
new file mode 100644
index 00000000..60c9556d
--- /dev/null
+++ b/src/gui/main/app_state/app_state.py
@@ -0,0 +1,17 @@
+from typing import List
+
+from pydantic import BaseModel
+
+
+class AppState(BaseModel):
+ session_id: str = None
+ available_cameras: List[str] = []
+ selected_cameras: List[str] = []
+ camera_configs: dict = {}
+ main_window_height: int = None
+ main_window_width: int = None
+ use_previous_calibration: bool = False
+ rotate_videos_dict: dict = {}
+
+
+APP_STATE = AppState()
diff --git a/src/gui/main/custom_widgets/single_camera_widget.py b/src/gui/main/custom_widgets/single_camera_widget.py
new file mode 100644
index 00000000..74533eb2
--- /dev/null
+++ b/src/gui/main/custom_widgets/single_camera_widget.py
@@ -0,0 +1,87 @@
+import enum
+
+from PyQt6.QtCore import pyqtSignal
+from PyQt6.QtGui import QPixmap
+from PyQt6.QtWidgets import QHBoxLayout, QLabel, QWidget
+
+from src.config.webcam_config import WebcamConfig
+from src.gui.main.app import get_qt_app
+from src.gui.main.workers.cam_charuco_frame_thread_worker import (
+ CamCharucoFrameThreadWorker,
+)
+from src.gui.main.workers.cam_frame_worker import CamFrameWorker
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class WorkerType(enum.Enum):
+ FRAME_CAPTURE = 0
+ CHARUCO = 1
+
+
+def construct_worker(worker_type: WorkerType):
+ if worker_type.CHARUCO:
+ return CamCharucoFrameThreadWorker
+
+ if worker_type.FRAME_CAPTURE:
+ return CamFrameWorker
+
+ raise Exception("What?")
+
+
+class CameraWidget(QWidget):
+ started = pyqtSignal()
+
+ def __init__(self, webcam_config: WebcamConfig):
+ logger.info(f"Creating camera widget with WebcamConfig: {webcam_config}")
+ super().__init__()
+ self._webcam_config = webcam_config
+ self._camera_id = webcam_config.webcam_id
+
+ self._worker = self._init_frame_worker()
+ self._video = QLabel()
+
+ layout = QHBoxLayout()
+ layout.addWidget(self._video)
+
+ self.setLayout(layout)
+
+ get_qt_app().aboutToQuit.connect(self.quit)
+
+ @property
+ def camera_id(self):
+ return self._camera_id
+
+ @property
+ def should_record_frames(self):
+ return self._worker.should_save_frames
+
+ @property
+ def video_recorder(self):
+ return self._worker.video_recorder
+
+ def start_saving_frames(self):
+ self._worker.start_saving_frames()
+
+ def stop_saving_frames(self):
+ self._worker.stop_saving_frames()
+
+ def reset_video_recorder(self):
+ self._worker.reset_video_recorder()
+
+ def start(self):
+ self._worker.start()
+ self.started.emit()
+
+ def quit(self):
+ self._worker.quit()
+
+ def _init_frame_worker(self):
+ worker = construct_worker(WorkerType.CHARUCO)(self._webcam_config)
+ worker.image_updated_signal.connect(self._handle_image_update)
+ return worker
+
+ def _handle_image_update(self, image):
+ self._video.setPixmap(QPixmap.fromImage(image))
diff --git a/src/gui/main/main.py b/src/gui/main/main.py
index a5c6067b..bc6b9269 100644
--- a/src/gui/main/main.py
+++ b/src/gui/main/main.py
@@ -1,12 +1,16 @@
+import logging
import signal
import sys
from PyQt6.QtCore import QTimer
from PyQt6.QtWidgets import QApplication
-# from src.api.routes.session.session_router import visualize_session_offline
from src.gui.main.app import get_qt_app
-from src.gui.main.layout.main_window import MainWindow
+from src.gui.main.main_window.main_window import MainWindow
+
+logger = logging.getLogger(__name__)
+
+gui_loop_count = -1
def sigint_handler(*args):
@@ -14,14 +18,21 @@ def sigint_handler(*args):
QApplication.quit()
+def log_gui_loop():
+ global gui_loop_count
+ gui_loop_count += 1
+ if gui_loop_count % 10 == 0:
+ logger.debug("GUI loop {}".format(gui_loop_count))
+
+
if __name__ == "__main__":
+ logger.info("Starting main...")
signal.signal(signal.SIGINT, sigint_handler)
app = get_qt_app()
timer = QTimer()
timer.start(500)
+ # timer.timeout.connect(log_gui_loop) # Let the interpreter run each 500 ms.
timer.timeout.connect(lambda: None) # Let the interpreter run each 500 ms.
win = MainWindow()
win.show()
sys.exit(app.exec())
- # app.exec()
- # visualize_session_offline()
diff --git a/src/gui/main/main_window/__init__.py b/src/gui/main/main_window/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/gui/main/main_window/left_panel_controls/__init__.py b/src/gui/main/main_window/left_panel_controls/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/gui/main/main_window/left_panel_controls/control_panel.py b/src/gui/main/main_window/left_panel_controls/control_panel.py
new file mode 100644
index 00000000..9caa7acd
--- /dev/null
+++ b/src/gui/main/main_window/left_panel_controls/control_panel.py
@@ -0,0 +1,110 @@
+from typing import List
+
+from PyQt6.QtWidgets import (
+ QFrame,
+ QVBoxLayout,
+ QLabel,
+ QToolBox,
+)
+
+from src.cameras.detection.models import FoundCamerasResponse
+from src.config.webcam_config import WebcamConfig
+from src.gui.main.main_window.left_panel_controls.toolbox_widgets.calibrate_capture_volume_panel import (
+ CalibrateCaptureVolumePanel,
+)
+from src.gui.main.main_window.left_panel_controls.toolbox_widgets.camera_setup_control_panel import (
+ CameraSetupControlPanel,
+)
+from src.gui.main.main_window.left_panel_controls.toolbox_widgets.create_or_load_new_session_panel import (
+ CreateOrLoadNewSessionPanel,
+)
+from src.gui.main.main_window.left_panel_controls.toolbox_widgets.process_session_data_panel import (
+ ProcessSessionDataPanel,
+)
+from src.gui.main.main_window.left_panel_controls.toolbox_widgets.record_synchronized_videos_panel import (
+ RecordSynchronizedVideosPanel,
+)
+
+from src.gui.main.qt_utils.clear_layout import clear_layout
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class ControlPanel:
+ def __init__(self):
+ self._frame = QFrame()
+ self._frame.setFrameShape(QFrame.Shape.StyledPanel)
+ self._layout = QVBoxLayout()
+ self._frame.setLayout(self._layout)
+
+ self._create_toolbox_panels()
+ self._toolbox_widget = self._create_toolbox_widget()
+ self._layout.addWidget(self._toolbox_widget)
+
+ @property
+ def frame(self):
+ return self._frame
+
+ @property
+ def camera_setup_control_panel(self):
+ return self._camera_setup_control_panel
+
+ @property
+ def calibrate_capture_volume_panel(self):
+ return self._calibrate_capture_volume_panel
+
+ @property
+ def record_synchronized_videos_panel(self):
+ return self._record_synchronized_videos_panel
+
+ @property
+ def process_session_data_panel(self):
+ return self._process_session_data_panel
+
+ @property
+ def toolbox_widget(self):
+ return self._toolbox_widget
+
+ def handle_found_camera_response(
+ self, found_cameras_response: FoundCamerasResponse
+ ):
+ self._camera_setup_control_panel.handle_found_cameras_response(
+ found_cameras_response
+ )
+
+ def _start_standard_workflow(self):
+ clear_layout(self._layout)
+ self._create_toolbox_widget()
+
+ def _create_toolbox_widget(self):
+ toolbox_widget = QToolBox()
+
+ toolbox_widget.addItem(
+ self._create_or_load_new_session_panel, "Create or Load Session"
+ )
+
+ toolbox_widget.addItem(self._camera_setup_control_panel, "Camera Setup")
+
+ toolbox_widget.addItem(
+ self._calibrate_capture_volume_panel, "Calibrate Capture Volume"
+ )
+
+ toolbox_widget.addItem(
+ self._record_synchronized_videos_panel, "Record Synchronized Videos"
+ )
+ toolbox_widget.addItem(self._process_session_data_panel, "Process Session Data")
+
+ toolbox_widget.addItem(
+ QLabel("View Motion Capture Data"), "View Motion Capture Data"
+ )
+
+ return toolbox_widget
+
+ def _create_toolbox_panels(self):
+ self._create_or_load_new_session_panel = CreateOrLoadNewSessionPanel()
+ self._camera_setup_control_panel = CameraSetupControlPanel()
+ self._calibrate_capture_volume_panel = CalibrateCaptureVolumePanel()
+ self._record_synchronized_videos_panel = RecordSynchronizedVideosPanel()
+ self._process_session_data_panel = ProcessSessionDataPanel()
diff --git a/src/gui/main/main_window/left_panel_controls/toolbox_widgets/__init__.py b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/src/gui/main/main_window/left_panel_controls/toolbox_widgets/calibrate_capture_volume_panel.py b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/calibrate_capture_volume_panel.py
new file mode 100644
index 00000000..75dc239f
--- /dev/null
+++ b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/calibrate_capture_volume_panel.py
@@ -0,0 +1,98 @@
+from PyQt6.QtWidgets import (
+ QWidget,
+ QVBoxLayout,
+ QPushButton,
+ QCheckBox,
+ QFormLayout,
+ QLineEdit,
+)
+
+from src.core_processes.capture_volume_calibration.charuco_default_values import (
+ default_charuco_square_size_mm,
+)
+from src.gui.main.app_state.app_state import APP_STATE
+from src.gui.main.workers.anipose_calibration_thread_worker import (
+ AniposeCalibrationThreadWorker,
+)
+
+
+class CalibrateCaptureVolumePanel(QWidget):
+ def __init__(self):
+ super().__init__()
+
+ self._central_layout = QVBoxLayout()
+
+ self._use_previous_calibration_checkbox = (
+ self._create_use_previous_calibration_checkbox()
+ )
+ self._central_layout.addWidget(self._use_previous_calibration_checkbox)
+
+ # start/stop recording button layout
+ record_button_layout = QVBoxLayout()
+ self._central_layout.addLayout(record_button_layout)
+
+ self._start_recording_button = QPushButton("Begin Recording")
+ record_button_layout.addWidget(self._start_recording_button)
+
+ self._stop_recording_button = QPushButton("Stop Recording")
+ self._stop_recording_button.setEnabled(False)
+ record_button_layout.addWidget(self._stop_recording_button)
+
+ self._charuco_square_size_form_layout = QFormLayout()
+ self._charuco_square_size_line_edit_widget = QLineEdit()
+ self._charuco_square_size_line_edit_widget.setText(
+ str(default_charuco_square_size_mm)
+ )
+ self._charuco_square_size_form_layout.addRow(
+ "Charuco Square Size (mm):", self._charuco_square_size_line_edit_widget
+ )
+
+ self._central_layout.addLayout(self._charuco_square_size_form_layout)
+
+ self._calibrate_capture_volume_from_videos_button = QPushButton(
+ "Calibrate Capture Volume From Videos"
+ )
+
+ self._calibrate_capture_volume_from_videos_button.setEnabled(False)
+ self._central_layout.addWidget(
+ self._calibrate_capture_volume_from_videos_button
+ )
+
+ self.setLayout(self._central_layout)
+
+ @property
+ def start_recording_button(self):
+ return self._start_recording_button
+
+ @property
+ def stop_recording_button(self):
+ return self._stop_recording_button
+
+ @property
+ def calibrate_capture_volume_from_videos_button(self):
+ return self._calibrate_capture_volume_from_videos_button
+
+ @property
+ def use_previous_calibration_box_is_checked(self):
+ return self._use_previous_calibration_checkbox.isChecked()
+
+ @property
+ def charuco_square_size(self):
+ return self._charuco_square_size_line_edit_widget.text()
+
+ def _create_use_previous_calibration_checkbox(self):
+ previous_calibration_checkbox = QCheckBox("Use Previous Calibration")
+ previous_calibration_checkbox.setChecked(False)
+
+ return previous_calibration_checkbox
+
+ def change_button_states_on_record_start(self):
+ self._start_recording_button.setEnabled(False)
+ self._start_recording_button.setText("Recording...")
+ self._stop_recording_button.setEnabled(True)
+
+ def change_button_states_on_record_stop(self):
+ self._stop_recording_button.setEnabled(False)
+ self._start_recording_button.setEnabled(True)
+ self._start_recording_button.setText("Begin Recording")
+ self._calibrate_capture_volume_from_videos_button.setEnabled(True)
diff --git a/src/gui/main/main_window/left_panel_controls/toolbox_widgets/camera_setup_control_panel.py b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/camera_setup_control_panel.py
new file mode 100644
index 00000000..2c52fc1e
--- /dev/null
+++ b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/camera_setup_control_panel.py
@@ -0,0 +1,139 @@
+from typing import List, Dict
+
+from PyQt6.QtCore import pyqtSignal
+from PyQt6.QtWidgets import QVBoxLayout, QWidget, QPushButton
+from pyqtgraph.parametertree import ParameterTree, Parameter
+
+from src.cameras.detection.models import FoundCamerasResponse
+from src.config.webcam_config import WebcamConfig
+from src.gui.main.qt_utils.clear_layout import clear_layout
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class CameraSetupControlPanel(QWidget):
+ camera_parameters_updated_signal = pyqtSignal(dict)
+
+ def __init__(self):
+ super().__init__()
+ self._panel_layout = QVBoxLayout()
+ self.setLayout(self._panel_layout)
+
+ self._redetect_cameras_button = QPushButton("TO DO - Re-Detect Cameras")
+ self._redetect_cameras_button.setEnabled(False)
+ self._panel_layout.addWidget(self._redetect_cameras_button)
+
+ self._apply_settings_to_cameras_button = QPushButton(
+ "TO DO - Apply settings to cameras",
+ )
+ self._apply_settings_to_cameras_button.setEnabled(False)
+ self._panel_layout.addWidget(self._apply_settings_to_cameras_button)
+
+ self._parameter_tree_layout = QVBoxLayout()
+ self._parameter_tree_widget = ParameterTree()
+ self._parameter_tree_layout.addWidget(self._parameter_tree_widget)
+ self._panel_layout.addLayout(self._parameter_tree_layout)
+
+ @property
+ def apply_settings_to_cameras_button(self):
+ return self._apply_settings_to_cameras_button
+
+ @property
+ def redetect_cameras_button(self):
+ return self._redetect_cameras_button
+
+ def handle_found_cameras_response(
+ self, found_cameras_response: FoundCamerasResponse
+ ):
+ self._list_of_available_camera_ids = [
+ raw_cam.webcam_id for raw_cam in found_cameras_response.cameras_found_list
+ ]
+
+ logger.info(f"Found cameras with IDs: {self._list_of_available_camera_ids}")
+
+ self._dictionary_of_webcam_configs = {}
+ for camera_id in self._list_of_available_camera_ids:
+ self._dictionary_of_webcam_configs[camera_id] = WebcamConfig(
+ webcam_id=camera_id
+ )
+
+ self.update_camera_config_parameter_tree()
+
+ def update_camera_config_parameter_tree(self):
+ logger.info("Updating camera configs")
+ clear_layout(self._parameter_tree_layout)
+ self._parameter_tree_widget = ParameterTree()
+ self._parameter_tree_layout.addWidget(self._parameter_tree_widget)
+
+ self._camera_parameter_groups_dictionary = {}
+ for webcam_config in self._dictionary_of_webcam_configs.values():
+
+ self._camera_parameter_groups_dictionary[
+ webcam_config.webcam_id
+ ] = self._create_webcam_parameter_tree(webcam_config)
+
+ self._parameter_tree_widget.addParameters(
+ self._camera_parameter_groups_dictionary[webcam_config.webcam_id]
+ )
+
+ self.camera_parameters_updated_signal.emit(self._dictionary_of_webcam_configs)
+
+ def get_webcam_configs_from_parameter_tree(self):
+ new_selected_cameras_list = []
+ new_camera_configs_dict = {}
+
+ for (
+ camera_id,
+ camera_parameter_group,
+ ) in self._camera_parameter_groups_dictionary.items():
+ if camera_parameter_group.param("Use this camera?").value():
+ new_selected_cameras_list.append(camera_id)
+ try:
+ new_camera_configs_dict[camera_id] = WebcamConfig(
+ webcam_id=camera_id,
+ exposure=camera_parameter_group.param("Exposure").value(),
+ resolution_width=camera_parameter_group.param(
+ "Resolution Width"
+ ).value(),
+ resolution_height=camera_parameter_group.param(
+ "Resolution Height"
+ ).value(),
+ )
+ except:
+ new_camera_configs_dict[camera_id] = WebcamConfig(
+ webcam_id=camera_id
+ )
+ self._dictionary_of_webcam_configs = new_camera_configs_dict
+ self.camera_parameters_updated_signal.emit(self._dictionary_of_webcam_configs)
+
+ def _create_webcam_parameter_tree(self, webcam_config: WebcamConfig):
+ return Parameter.create(
+ name="Camera_" + str(webcam_config.webcam_id),
+ type="group",
+ children=[
+ dict(name="Use this camera?", type="bool", value=True),
+ # dict(name="Apply settings", type="action"),
+ dict(name="Exposure", type="int", value=webcam_config.exposure),
+ dict(
+ name="Resolution Width",
+ type="int",
+ value=webcam_config.resolution_width,
+ ),
+ dict(
+ name="Resolution Height",
+ type="int",
+ value=webcam_config.resolution_height,
+ ),
+ ],
+ )
+
+ def _create_webcam_parameter_tree_for_unselected_camera(self, webcam_id):
+ return Parameter.create(
+ name="Camera_" + str(webcam_id),
+ type="group",
+ children=[
+ dict(name="Use this camera?", type="bool", value=False),
+ ],
+ )
diff --git a/src/gui/main/main_window/left_panel_controls/toolbox_widgets/create_or_load_new_session_panel.py b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/create_or_load_new_session_panel.py
new file mode 100644
index 00000000..6848202a
--- /dev/null
+++ b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/create_or_load_new_session_panel.py
@@ -0,0 +1,63 @@
+from PyQt6.QtWidgets import (
+ QWidget,
+ QVBoxLayout,
+ QLabel,
+ QLineEdit,
+ QFormLayout,
+ QPushButton,
+)
+
+from src.config.home_dir import create_default_session_id
+from src.gui.main.styled_widgets.primary_button import PrimaryButton
+
+
+class CreateOrLoadNewSessionPanel(QWidget):
+ def __init__(self):
+ super().__init__()
+
+ central_layout = QVBoxLayout()
+
+ central_layout.addLayout(self._create_new_session_layout())
+
+ self._load_most_recent_session_button = QPushButton(
+ "TO DO - Load Most &Recent Session"
+ )
+ self._load_most_recent_session_button.setEnabled(False)
+ central_layout.addWidget(self._load_most_recent_session_button)
+
+ self._load_session_button = QPushButton("TO DO - &Load Session")
+ self._load_session_button.setEnabled(False)
+ central_layout.addWidget(self._load_session_button)
+
+ self._import_external_videos_button = QPushButton(
+ "TO DO - Import External &Videos"
+ )
+ self._import_external_videos_button.setEnabled(False)
+ central_layout.addWidget(self._import_external_videos_button)
+
+ self.setLayout(central_layout)
+
+ @property
+ def start_new_session_button(self):
+ return self._start_new_session_button
+
+ @property
+ def session_id_input_string(self):
+ return self._session_input.text()
+
+ def _create_session_input(self):
+ session_text_input = QLineEdit()
+ session_text_input.setText(create_default_session_id())
+ return session_text_input
+
+ def _create_new_session_layout(self):
+ layout = QVBoxLayout()
+
+ session_id_form_layout = QFormLayout()
+ self._session_input = self._create_session_input()
+ session_id_form_layout.addRow(QLabel("Session Id"), self._session_input)
+ layout.addLayout(session_id_form_layout)
+
+ self._start_new_session_button = PrimaryButton("&Start Session")
+ layout.addWidget(self._start_new_session_button)
+ return layout
diff --git a/src/gui/main/main_window/left_panel_controls/toolbox_widgets/process_session_data_panel.py b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/process_session_data_panel.py
new file mode 100644
index 00000000..317fbeef
--- /dev/null
+++ b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/process_session_data_panel.py
@@ -0,0 +1,104 @@
+import numpy as np
+from PyQt6 import QtCore
+from PyQt6.QtWidgets import QWidget, QVBoxLayout, QPushButton
+
+from src.export_stuff.blender_stuff.open_session_in_blender import (
+ open_session_in_blender,
+)
+from src.gui.main.app_state.app_state import APP_STATE
+
+
+class ProcessSessionDataPanel(QWidget):
+
+ data_2d_done_signal = QtCore.pyqtSignal(str)
+ data_3d_done_signal = QtCore.pyqtSignal(str)
+
+ def __init__(self):
+ super().__init__()
+
+ self._layout = QVBoxLayout()
+ self.setLayout(self._layout)
+
+ processing_buttons_layout = QVBoxLayout()
+ self._layout.addLayout(processing_buttons_layout)
+
+ # self._process_all_button = QPushButton("Process All")
+ # self._process_all_button.setEnabled(True)
+ # self._process_all_button.clicked.connect(self._process_all)
+ # processing_buttons_layout.addWidget(self._process_all_button)
+
+ self._detect_2d_skeletons_button = QPushButton("Detect 2d Skeletons in Videos")
+ self._detect_2d_skeletons_button.setEnabled(True)
+ processing_buttons_layout.addWidget(self._detect_2d_skeletons_button)
+
+ self._triangulate_3d_data_button = QPushButton("Triangulate 3d Data")
+ self._triangulate_3d_data_button.setEnabled(True)
+ processing_buttons_layout.addWidget(self._triangulate_3d_data_button)
+
+ # self._visualize_freemocap_session_button = QPushButton(
+ # "Visualize Freemocap Session"
+ # )
+ # self._visualize_freemocap_session_button.setEnabled(True)
+ # self._visualize_freemocap_session_button.clicked.connect(
+ # self._visualize_freemocap_session
+ # )
+ # processing_buttons_layout.addWidget(self._visualize_freemocap_session_button)
+
+ self._open_in_blender_button = QPushButton("Open Session in Blender")
+ self._open_in_blender_button.setEnabled(True)
+ processing_buttons_layout.addWidget(self._open_in_blender_button)
+
+ @property
+ def detect_2d_skeletons_button(self):
+ return self._detect_2d_skeletons_button
+
+ @property
+ def triangulate_3d_data_button(self):
+ return self._triangulate_3d_data_button
+
+ @property
+ def open_in_blender_button(self):
+ return self._open_in_blender_button
+
+ def _reconstruct_3d_skeletons(self):
+ pass
+
+ # session_orchestrator = SessionPipelineOrchestrator(
+ # session_id=APP_STATE.session_id
+ # )
+ #
+ # if APP_STATE.use_previous_calibration:
+ # session_orchestrator.anipose_camera_calibration_object = (
+ # CalibrationPipelineOrchestrator().load_most_recent_anipose_calibration_toml()
+ # )
+ # else:
+ # session_orchestrator.anipose_camera_calibration_object = (
+ # CalibrationPipelineOrchestrator().load_calibration_from_session_id(
+ # APP_STATE.session_id
+ # )
+ # )
+ #
+ # session_orchestrator.mediapipe2d_numCams_numFrames_numTrackedPoints_XY = (
+ # load_mediapipe2d_data(APP_STATE.session_id)
+ # )
+ # path_to_3d_data_npy = session_orchestrator.reconstruct3d_from_2d_data_offline()
+ #
+ # self.data_3d_done_signal.emit(path_to_3d_data_npy)
+ #
+ # self._open_in_blender_button.setEnabled(True)
+
+ def _visualize_freemocap_session(self):
+ pass
+ # mediapipe3d_data_payload = load_mediapipe3d_skeleton_data(APP_STATE.session_id)
+ #
+ # mediapipe3d_skeleton_nFrames_nTrajectories_xyz =
+ # mediapipe3d_data_payload.data3d_numFrames_numTrackedPoints_XYZ
+ # mediapipe3d_skeleton_nFrames_nTrajectories_reprojectionError =
+ # mediapipe3d_data_payload.data3d_numFrames_numTrackedPoint_reprojectionError
+ #
+ # visualize_skeleton_dialog = VisualizeSkeleton(
+ # mediapipe_skel_fr_mar_xyz=mediapipe3d_skeleton_nFrames_nTrajectories_xyz)
+ #
+ # get_qt_app().quit()
+ # visualize_skeleton_dialog.exec()
+ # visualize_skeleton_dialog.start_animation()
diff --git a/src/gui/main/main_window/left_panel_controls/toolbox_widgets/record_synchronized_videos_panel.py b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/record_synchronized_videos_panel.py
new file mode 100644
index 00000000..b3701cb5
--- /dev/null
+++ b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/record_synchronized_videos_panel.py
@@ -0,0 +1,42 @@
+from PyQt6.QtWidgets import (
+ QPushButton,
+ QVBoxLayout,
+ QWidget,
+)
+
+
+class RecordSynchronizedVideosPanel(QWidget):
+ def __init__(self):
+ super().__init__()
+
+ self._layout = QVBoxLayout()
+ self.setLayout(self._layout)
+
+ # start/stop recording button layout
+ record_button_layout = QVBoxLayout()
+ self._layout.addLayout(record_button_layout)
+
+ self._start_recording_button = QPushButton("Begin Recording")
+ record_button_layout.addWidget(self._start_recording_button)
+
+ self._stop_recording_button = QPushButton("Stop Recording")
+ self._stop_recording_button.setEnabled(False)
+ record_button_layout.addWidget(self._stop_recording_button)
+
+ @property
+ def start_recording_button(self):
+ return self._start_recording_button
+
+ @property
+ def stop_recording_button(self):
+ return self._stop_recording_button
+
+ def change_button_states_on_record_start(self):
+ self._start_recording_button.setEnabled(False)
+ self._start_recording_button.setText("Recording...")
+ self._stop_recording_button.setEnabled(True)
+
+ def change_button_states_on_record_stop(self):
+ self._stop_recording_button.setEnabled(False)
+ self._start_recording_button.setEnabled(True)
+ self._start_recording_button.setText("Begin Recording")
diff --git a/src/gui/main/main_window/left_panel_controls/toolbox_widgets/welcome_tab.py b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/welcome_tab.py
new file mode 100644
index 00000000..76074a30
--- /dev/null
+++ b/src/gui/main/main_window/left_panel_controls/toolbox_widgets/welcome_tab.py
@@ -0,0 +1,40 @@
+from PyQt6.QtWidgets import (
+ QWidget,
+ QVBoxLayout,
+ QHBoxLayout,
+ QLabel,
+ QCheckBox,
+ QLineEdit,
+ QPushButton,
+)
+
+from src.config.home_dir import create_default_session_id
+from src.gui.icis_conference_main.shared_widgets.primary_button import PrimaryButton
+from src.gui.main.app_state.app_state import APP_STATE
+from src.gui.main.styled_widgets.page_title import PageTitle
+
+
+class SelectWorkflowScreen(QWidget):
+ def __init__(self):
+ super().__init__()
+
+ container_layout = QVBoxLayout()
+
+ self._start_new_session_button = QPushButton("&Start New Session")
+ container_layout.addWidget(self._start_new_session_button)
+
+ self._load_previous_session_button = QPushButton(
+ "TO DO - &Load Previous Session"
+ )
+ self._load_previous_session_button.setEnabled(False)
+ container_layout.addWidget(self._load_previous_session_button)
+
+ self._import_external_videos = QPushButton("TO DO - &Import External Videos")
+ self._import_external_videos.setEnabled(False)
+ container_layout.addWidget(self._import_external_videos)
+
+ self.setLayout(container_layout)
+
+ @property
+ def start_new_session_button(self):
+ return self._start_new_session_button
diff --git a/src/gui/main/main_window/main_window.py b/src/gui/main/main_window/main_window.py
new file mode 100644
index 00000000..7930fc4a
--- /dev/null
+++ b/src/gui/main/main_window/main_window.py
@@ -0,0 +1,234 @@
+from PyQt6.QtWidgets import QMainWindow, QHBoxLayout, QWidget
+
+from src.config.home_dir import (
+ get_calibration_videos_folder_path,
+ get_synchronized_videos_folder_path,
+ get_session_folder_path,
+ get_session_calibration_toml_file_path,
+ get_output_data_folder_path,
+)
+from src.core_processes.capture_volume_calibration.get_anipose_calibration_object import (
+ load_most_recent_anipose_calibration_toml,
+ load_calibration_from_session_id,
+)
+from src.core_processes.mediapipe_2d_skeleton_detector.load_mediapipe2d_data import (
+ load_mediapipe2d_data,
+)
+from src.export_stuff.blender_stuff.open_session_in_blender import (
+ open_session_in_blender,
+)
+from src.gui.main.main_window.left_panel_controls.control_panel import ControlPanel
+from src.gui.main.main_window.right_side_panel.right_side_panel import (
+ RightSidePanel,
+)
+from src.gui.main.main_window.middle_panel_viewers.camera_view_panel import (
+ CameraViewPanel,
+)
+
+import logging
+
+from src.gui.main.workers.thread_worker_manager import ThreadWorkerManager
+
+logger = logging.getLogger(__name__)
+
+
+class MainWindow(QMainWindow):
+ def __init__(self):
+ logger.info("Creating main window")
+
+ super().__init__()
+ self.setWindowTitle("freemocap")
+ self._main_window_width = int(1920 * 0.8)
+ self._main_window_height = int(1080 * 0.8)
+ self.setGeometry(0, 0, self._main_window_width, self._main_window_height)
+ self._main_layout = self._create_main_layout()
+
+ # control panel
+ self._control_panel = self._create_control_panel()
+ self._main_layout.addWidget(self._control_panel.frame)
+
+ # viewing panel
+ self._camera_view_panel = self._create_cameras_view_panel()
+ self._main_layout.addWidget(self._camera_view_panel.frame)
+
+ # jupyter console panel
+ self._right_side_panel = self._create_right_side_panel()
+ self._main_layout.addWidget(self._right_side_panel.frame)
+
+ self._thread_worker_manager = ThreadWorkerManager()
+
+ self._connect_signals_to_stuff()
+ self._connect_buttons_to_stuff()
+
+ def _create_main_layout(self):
+ main_layout = QHBoxLayout()
+ widget = QWidget()
+ widget.setLayout(main_layout)
+ self.setCentralWidget(widget)
+ return main_layout
+
+ def _create_control_panel(self):
+ panel = ControlPanel()
+ panel.frame.setFixedWidth(self._main_window_width * 0.2)
+ panel.frame.setFixedHeight(self._main_window_height)
+ return panel
+
+ def _create_cameras_view_panel(self):
+ panel = CameraViewPanel()
+ panel.frame.setFixedWidth(self._main_window_width * 0.4)
+ panel.frame.setFixedHeight(self._main_window_height)
+ return panel
+
+ def _create_right_side_panel(self):
+ panel = RightSidePanel()
+ panel.frame.setFixedWidth(self._main_window_width * 0.4)
+ panel.frame.setFixedHeight(self._main_window_height)
+ return panel
+
+ def _connect_buttons_to_stuff(self):
+ logger.info("Connecting buttons to stuff")
+
+ self._control_panel._create_or_load_new_session_panel.start_new_session_button.clicked.connect(
+ self._start_new_session
+ )
+
+ # Camera Control Panel
+ self._control_panel.camera_setup_control_panel.apply_settings_to_cameras_button.clicked.connect(
+ self._control_panel.camera_setup_control_panel.get_webcam_configs_from_parameter_tree
+ )
+
+ # Calibration panel
+ self._control_panel.calibrate_capture_volume_panel.start_recording_button.clicked.connect(
+ lambda: self._start_recording_videos(
+ panel=self._control_panel.calibrate_capture_volume_panel
+ )
+ )
+
+ self._control_panel.calibrate_capture_volume_panel.stop_recording_button.clicked.connect(
+ lambda: self._stop_recording_videos(
+ panel=self._control_panel.calibrate_capture_volume_panel,
+ calibration_videos=True,
+ )
+ )
+
+ self._control_panel.calibrate_capture_volume_panel.calibrate_capture_volume_from_videos_button.clicked.connect(
+ self._setup_and_launch_anipose_calibration_thread_worker
+ )
+
+ # RecordVideos panel
+ self._control_panel.record_synchronized_videos_panel.start_recording_button.clicked.connect(
+ lambda: self._start_recording_videos(
+ panel=self._control_panel.record_synchronized_videos_panel,
+ )
+ )
+
+ self._control_panel.record_synchronized_videos_panel.stop_recording_button.clicked.connect(
+ lambda: self._stop_recording_videos(
+ panel=self._control_panel.record_synchronized_videos_panel
+ )
+ )
+
+ # ProcessVideos panel
+ self._control_panel.process_session_data_panel.detect_2d_skeletons_button.clicked.connect(
+ self._setup_and_launch_mediapipe_2d_detection_thread_worker
+ )
+
+ self._control_panel.process_session_data_panel.triangulate_3d_data_button.clicked.connect(
+ self._setup_and_launch_triangulate_3d_thread_worker
+ )
+
+ self._control_panel.process_session_data_panel.open_in_blender_button.clicked.connect(
+ self._launch_blender_export_subprocess
+ )
+
+ def _connect_signals_to_stuff(self):
+ logger.info("Connecting signals to stuff")
+
+ self._thread_worker_manager.camera_detection_finished.connect(
+ self._control_panel.handle_found_camera_response
+ )
+
+ self._control_panel.camera_setup_control_panel.camera_parameters_updated_signal.connect(
+ self._thread_worker_manager.create_camera_widgets_with_running_threads
+ )
+
+ self._thread_worker_manager.cameras_connected_signal.connect(
+ self._camera_view_panel.show_camera_streams
+ )
+
+ def _start_new_session(self):
+ self._session_id = (
+ self._control_panel._create_or_load_new_session_panel.session_id_input_string
+ )
+
+ session_path = get_session_folder_path(self._session_id, create_folder=True)
+ self._right_side_panel.file_system_view_widget.set_session_path_as_root(
+ session_path
+ )
+ self._thread_worker_manager.launch_detect_cameras_worker()
+ self._control_panel.toolbox_widget.setCurrentWidget(
+ self._control_panel.camera_setup_control_panel
+ )
+
+ def _start_recording_videos(self, panel):
+ panel.change_button_states_on_record_start()
+ self._thread_worker_manager.start_recording_videos()
+
+ def _stop_recording_videos(self, panel, calibration_videos=False):
+ panel.change_button_states_on_record_stop()
+ self._thread_worker_manager.stop_recording_videos()
+
+ if calibration_videos:
+ path_to_save_videos = get_calibration_videos_folder_path(self._session_id)
+ else:
+ path_to_save_videos = get_synchronized_videos_folder_path(self._session_id)
+
+ self._thread_worker_manager.launch_save_videos_thread_worker(
+ path_to_save_videos
+ )
+
+ def _setup_and_launch_anipose_calibration_thread_worker(self):
+ calibration_videos_folder_path = get_calibration_videos_folder_path(
+ self._session_id
+ )
+ self._thread_worker_manager.launch_anipose_calibration_thread_worker(
+ calibration_videos_folder_path=calibration_videos_folder_path,
+ charuco_square_size_mm=float(
+ self._control_panel.calibrate_capture_volume_panel.charuco_square_size
+ ),
+ )
+
+ def _setup_and_launch_mediapipe_2d_detection_thread_worker(self):
+ synchronized_videos_folder_path = get_synchronized_videos_folder_path(
+ self._session_id
+ )
+ output_data_folder_path = get_output_data_folder_path(self._session_id)
+ self._thread_worker_manager.launch_detect_2d_skeletons_thread_worker(
+ synchronized_videos_folder_path=synchronized_videos_folder_path,
+ output_data_folder_path=output_data_folder_path,
+ )
+
+ def _setup_and_launch_triangulate_3d_thread_worker(self):
+ if (
+ self._control_panel.calibrate_capture_volume_panel.use_previous_calibration_box_is_checked
+ ):
+ anipose_calibration_object = load_most_recent_anipose_calibration_toml(
+ get_session_folder_path(self._session_id)
+ )
+ else:
+ anipose_calibration_object = load_calibration_from_session_id(
+ get_session_calibration_toml_file_path(self._session_id)
+ )
+
+ output_data_folder_path = get_output_data_folder_path(self._session_id)
+ mediapipe_2d_data = load_mediapipe2d_data(output_data_folder_path)
+
+ self._thread_worker_manager.launch_triangulate_3d_data_thread_worker(
+ anipose_calibration_object=anipose_calibration_object,
+ mediapipe_2d_data=mediapipe_2d_data,
+ output_data_folder_path=output_data_folder_path,
+ )
+
+ def _launch_blender_export_subprocess(self):
+ print(f"Open in Blender : {self._session_id}")
+ open_session_in_blender(self._session_id)
diff --git a/src/gui/main/main_window/middle_panel_viewers/camera_stream_grid_view.py b/src/gui/main/main_window/middle_panel_viewers/camera_stream_grid_view.py
new file mode 100644
index 00000000..f08c25fe
--- /dev/null
+++ b/src/gui/main/main_window/middle_panel_viewers/camera_stream_grid_view.py
@@ -0,0 +1,61 @@
+from typing import List, Dict
+
+import numpy as np
+from PyQt6.QtCore import pyqtSignal
+from PyQt6.QtWidgets import QWidget, QGridLayout, QVBoxLayout, QLabel
+
+from src.cameras.detection.models import FoundCamerasResponse
+from src.cameras.save_synchronized_videos import save_synchronized_videos
+from src.config.webcam_config import WebcamConfig
+from src.gui.main.app_state.app_state import APP_STATE
+from src.gui.main.custom_widgets.single_camera_widget import CameraWidget
+from src.gui.main.qt_utils.clear_layout import clear_layout
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class CameraStreamGridView(QWidget):
+ cameras_connected_signal = pyqtSignal()
+
+ def __init__(self):
+ super().__init__()
+ self._camera_widgets = []
+
+ self._camera_stream_layout = QVBoxLayout()
+ self.setLayout(self._camera_stream_layout)
+
+ @property
+ def video_recorders(self):
+ return [cam.video_recorder for cam in self._camera_widgets]
+
+ def show_camera_streams(
+ self, dictionary_of_single_camera_layouts=(Dict[str, QVBoxLayout])
+ ):
+ clear_layout(self._camera_stream_layout)
+ for single_camera_layout in dictionary_of_single_camera_layouts.values():
+ self._camera_stream_layout.addLayout(single_camera_layout)
+
+ def close_all_camera_streams(self):
+ for camera_widget in self._camera_widgets:
+ camera_widget.quit()
+
+ def start_recording_videos(self):
+ for camera_widget in self._camera_widgets:
+ camera_widget.start_saving_frames()
+
+ def stop_recording_videos(self):
+ for camera_widget in self._camera_widgets:
+ camera_widget.stop_saving_frames()
+
+ def save_synchronized_videos(self):
+ video_recorders = []
+ for cam in self._camera_widgets:
+ video_recorders.append(cam.video_recorder)
+
+ def close_and_reconnect_to_cameras(self):
+ self.close_all_camera_streams()
+ self._camera_widgets = []
+ clear_layout(self._camera_stream_layout)
+ self.connect_to_camera_streams()
diff --git a/src/gui/main/main_window/middle_panel_viewers/camera_view_panel.py b/src/gui/main/main_window/middle_panel_viewers/camera_view_panel.py
new file mode 100644
index 00000000..f0539152
--- /dev/null
+++ b/src/gui/main/main_window/middle_panel_viewers/camera_view_panel.py
@@ -0,0 +1,65 @@
+import time
+
+from PyQt6.QtWidgets import QFrame, QVBoxLayout, QWidget
+
+
+from src.cameras.detection.models import FoundCamerasResponse
+from src.config.webcam_config import WebcamConfig
+
+from src.gui.main.main_window.middle_panel_viewers.camera_stream_grid_view import (
+ CameraStreamGridView,
+)
+from src.gui.main.qt_utils.clear_layout import clear_layout
+from src.gui.main.styled_widgets.page_title import PageTitle
+from src.gui.main.workers.cam_detection_thread_worker import CameraDetectionThreadWorker
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class CameraViewPanel(QWidget):
+ def __init__(self):
+ super().__init__()
+ self._frame = QFrame()
+ self._frame.setFrameShape(QFrame.Shape.StyledPanel)
+ self._layout = QVBoxLayout()
+ self._frame.setLayout(self._layout)
+
+ self._welcome_to_freemocap_title_widget = self._welcome_to_freemocap_title()
+ self._central_layout = QVBoxLayout()
+ self._central_layout.addWidget(self._welcome_to_freemocap_title_widget)
+ self._layout.addLayout(self._central_layout)
+
+ self._camera_stream_grid_view = CameraStreamGridView()
+ self._camera_stream_grid_view.cameras_connected_signal.connect(
+ self._show_camera_stream_grid_view
+ )
+
+ @property
+ def frame(self):
+ return self._frame
+
+ @property
+ def camera_stream_grid_view(self):
+ return self._camera_stream_grid_view
+
+ def _welcome_to_freemocap_title(self):
+ session_title = PageTitle(
+ "Welcome to FreeMoCap! \n \U00002728 \U0001F480 \U00002728 "
+ )
+ return session_title
+
+ def _show_camera_stream_grid_view(self):
+ logger.info("Showing camera stream grid view")
+ clear_layout(self._central_layout)
+ self._central_layout.addWidget(self._camera_stream_grid_view)
+
+ def reconnect_to_cameras(self):
+ self._camera_stream_grid_view.close_and_reconnect_to_cameras()
+
+ def show_camera_streams(self, dictionary_of_single_camera_layouts):
+ self._camera_stream_grid_view.show_camera_streams(
+ dictionary_of_single_camera_layouts
+ )
+ self._show_camera_stream_grid_view()
diff --git a/src/gui/main/main_window/right_side_panel/file_system_view_widget.py b/src/gui/main/main_window/right_side_panel/file_system_view_widget.py
new file mode 100644
index 00000000..b50a0baf
--- /dev/null
+++ b/src/gui/main/main_window/right_side_panel/file_system_view_widget.py
@@ -0,0 +1,52 @@
+import os
+import sys
+from pathlib import Path
+from typing import Union
+
+from PyQt6.QtCore import Qt
+from PyQt6.QtGui import QFileSystemModel
+from PyQt6.QtWidgets import QWidget, QTreeView, QVBoxLayout, QMenu
+from qtpy import QtGui
+
+from src.config.home_dir import get_freemocap_data_folder_path, get_session_folder_path
+from src.gui.main.app_state.app_state import APP_STATE
+
+
+class FileSystemViewWidget(QWidget):
+ def __init__(self):
+ super().__init__()
+ layout = QVBoxLayout()
+ self.setLayout(layout)
+
+ self.setWindowTitle("File System Viewer")
+ # self.setGeometry(300, 300, appWidth, appHeight)
+
+ self._file_system_model = QFileSystemModel()
+ self._tree_view_widget = QTreeView()
+ layout.addWidget(self._tree_view_widget)
+
+ self._tree_view_widget.setContextMenuPolicy(Qt.CustomContextMenu)
+ self._tree_view_widget.customContextMenuRequested.connect(self._context_menu)
+ self._tree_view_widget.doubleClicked.connect(self.open_file)
+
+ self._tree_view_widget.setModel(self._file_system_model)
+ # self.tree.setColumnWidth(0, 250)
+ self._tree_view_widget.setAlternatingRowColors(True)
+ self._tree_view_widget.resizeColumnToContents(1)
+
+ def set_session_path_as_root(self, session_path: Union[str, Path]):
+ self._file_system_model.setRootPath(session_path)
+ self._tree_view_widget.setRootIndex(self._file_system_model.index(session_path))
+
+ def _context_menu(self):
+ menu = QMenu()
+ open = menu.addAction("Open file")
+ open.triggered.connect(self.open_file)
+
+ cursor = QtGui.QCursor()
+ menu.exec_(cursor.pos())
+
+ def open_file(self):
+ index = self._tree_view_widget.currentIndex()
+ file_path = self._file_system_model.filePath(index)
+ os.startfile(file_path)
diff --git a/src/gui/main/main_window/right_side_panel/jupyter_console_widget.py b/src/gui/main/main_window/right_side_panel/jupyter_console_widget.py
new file mode 100644
index 00000000..7bef080e
--- /dev/null
+++ b/src/gui/main/main_window/right_side_panel/jupyter_console_widget.py
@@ -0,0 +1,55 @@
+from typing import Dict
+
+import numpy as np
+from PyQt6.QtWidgets import QWidget
+from qtconsole.manager import QtKernelManager
+from qtconsole.rich_jupyter_widget import RichJupyterWidget
+
+from src.gui.main.app import get_qt_app
+
+
+def make_jupyter_widget_with_kernel():
+ """Start a kernel, connect to it, and create a RichJupyterWidget to use it"""
+ kernel_manager = QtKernelManager(kernel_name="python3")
+ kernel_manager.start_kernel()
+
+ kernel_client = kernel_manager.client()
+ kernel_client.start_channels()
+
+ jupyter_widget = RichJupyterWidget()
+ jupyter_widget.kernel_manager = kernel_manager
+ jupyter_widget.kernel_client = kernel_client
+ return jupyter_widget
+
+
+class PythonConsoleWidget(QWidget):
+ def __init__(self, dark_mode: bool = True):
+ super().__init__()
+
+ self._jupyter_console_widget = make_jupyter_widget_with_kernel()
+ self._import_stuff()
+
+ self.execute("import numpy as np")
+ self.execute("%whos", hidden=True)
+
+ get_qt_app().aboutToQuit.connect(self.shutdown_kernel)
+
+ if dark_mode:
+ self._jupyter_console_widget.set_default_style("linux")
+
+ @property
+ def jupyter_console_widget(self):
+ return self._jupyter_console_widget
+
+ def _import_stuff(self):
+ self.execute("import matplotlib.pyplot as plt")
+
+ def execute(self, code: str, hidden: bool = False):
+ self._jupyter_console_widget.execute(code, hidden=hidden)
+
+ def print(self, message: str):
+ self.execute(f"print('{message}')")
+
+ def shutdown_kernel(self):
+ self._jupyter_console_widget.kernel_client.stop_channels()
+ self._jupyter_console_widget.kernel_manager.shutdown_kernel()
diff --git a/src/gui/main/main_window/right_side_panel/right_side_panel.py b/src/gui/main/main_window/right_side_panel/right_side_panel.py
new file mode 100644
index 00000000..fe96eb15
--- /dev/null
+++ b/src/gui/main/main_window/right_side_panel/right_side_panel.py
@@ -0,0 +1,58 @@
+from PyQt6.QtWidgets import QFrame, QVBoxLayout, QTabWidget
+
+from src.gui.main.app import get_qt_app
+from src.gui.main.main_window.right_side_panel.file_system_view_widget import (
+ FileSystemViewWidget,
+)
+from src.gui.main.main_window.right_side_panel.jupyter_console_widget import (
+ PythonConsoleWidget,
+)
+
+
+class RightSidePanel:
+ def __init__(self):
+ self._frame = QFrame()
+ self._frame.setFrameShape(QFrame.Shape.StyledPanel)
+ self._main_layout = QVBoxLayout()
+ self._frame.setLayout(self._main_layout)
+
+ self._file_viewer_tab_widget = QTabWidget()
+ self._main_layout.addWidget(self._file_viewer_tab_widget)
+
+ self._mocap_file_system_view_widget = FileSystemViewWidget()
+ self._file_viewer_tab_widget.addTab(
+ self._mocap_file_system_view_widget, "Motion Capture Sessions"
+ )
+
+ self._log_and_console_tab_widget = QTabWidget()
+ self._main_layout.addWidget(self._log_and_console_tab_widget)
+
+ self._python_console_widget = self._create_python_console_widget()
+ self._log_and_console_tab_widget.addTab(
+ self._python_console_widget.jupyter_console_widget,
+ "iPython Jupyter Console",
+ )
+
+ self._log_widget = self._create_log_widget()
+
+ @property
+ def frame(self):
+ return self._frame
+
+ @property
+ def file_system_view_widget(self):
+ return self._mocap_file_system_view_widget
+
+ @property
+ def jupyter_console_widget(self):
+ return self._python_console_widget.jupyter_console_widget
+
+ def _create_python_console_widget(self):
+ # create jupyter console widget
+ python_console_widget = PythonConsoleWidget()
+ get_qt_app().aboutToQuit.connect(python_console_widget.shutdown_kernel)
+
+ return python_console_widget
+
+ def _create_log_widget(self):
+ pass
diff --git a/src/gui/main/qt_utils/clear_layout.py b/src/gui/main/qt_utils/clear_layout.py
index f7c1ba70..83da5fd2 100644
--- a/src/gui/main/qt_utils/clear_layout.py
+++ b/src/gui/main/qt_utils/clear_layout.py
@@ -1,4 +1,10 @@
-def clearLayout(layout):
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+def clear_layout(layout):
+ logger.debug(f"Clearing layout {layout}")
while layout.count():
child = layout.takeAt(0)
if child.widget():
diff --git a/src/gui/main/styled_widgets/page_title.py b/src/gui/main/styled_widgets/page_title.py
new file mode 100644
index 00000000..93183b5e
--- /dev/null
+++ b/src/gui/main/styled_widgets/page_title.py
@@ -0,0 +1,12 @@
+from PyQt6.QtCore import Qt
+from PyQt6.QtWidgets import QLabel
+
+from src.gui.icis_conference_main.qt_utils.set_font_size import set_font_size
+
+
+class PageTitle(QLabel):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ set_font_size(self, 24)
+ self.setAlignment(Qt.AlignmentFlag.AlignCenter)
+ self.setStyleSheet("padding-bottom: 20px")
diff --git a/src/gui/main/styled_widgets/primary_button.py b/src/gui/main/styled_widgets/primary_button.py
new file mode 100644
index 00000000..ad60b23f
--- /dev/null
+++ b/src/gui/main/styled_widgets/primary_button.py
@@ -0,0 +1,38 @@
+from PyQt6.QtWidgets import QPushButton
+
+
+active_primary_button_style_sheet = """
+ QPushButton {
+ background-color: #336e6d;
+ color: #ffffff;
+ border-radius: 4px;
+ min-height: 32px;
+ max-width: 160px;
+ font-weight: 400;
+ font-size: 16px;
+ }
+ QPushButton:hover {
+ background-color: #365d5f;
+ }
+ """
+
+not_active_primary_button_style_sheet = """
+ QPushButton {
+ background-color: 'lightgrey';
+ color: #ffffff;
+ border-radius: 4px;
+ min-height: 32px;
+ max-width: 160px;
+ font-weight: 400;
+ font-size: 16px;
+ }
+ QPushButton:hover {
+ background-color: 'lightgrey';
+ }
+ """
+
+
+class PrimaryButton(QPushButton):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.setStyleSheet(active_primary_button_style_sheet)
diff --git a/src/gui/main/workers/_minimal_example_thread_worker.py b/src/gui/main/workers/_minimal_example_thread_worker.py
new file mode 100644
index 00000000..bcdd7872
--- /dev/null
+++ b/src/gui/main/workers/_minimal_example_thread_worker.py
@@ -0,0 +1,15 @@
+from PyQt6.QtCore import QThread, pyqtSignal
+
+from src.cameras.detection.cam_singleton import get_or_create_cams
+from src.cameras.detection.models import FoundCamerasResponse
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class MinimalExampleThreadWorker(QThread):
+ finished = pyqtSignal(str)
+
+ def run(self):
+ self.finished.emit("Done!")
diff --git a/src/gui/main/workers/anipose_calibration_thread_worker.py b/src/gui/main/workers/anipose_calibration_thread_worker.py
new file mode 100644
index 00000000..ee74b478
--- /dev/null
+++ b/src/gui/main/workers/anipose_calibration_thread_worker.py
@@ -0,0 +1,50 @@
+import logging
+from pathlib import Path
+from typing import Union
+
+from PyQt6.QtCore import QThread, pyqtSignal
+
+from src.core_processes.capture_volume_calibration.run_anipose_capture_volume_calibration import (
+ run_anipose_capture_volume_calibration,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class AniposeCalibrationThreadWorker(QThread):
+ finished = pyqtSignal()
+ in_progress = pyqtSignal(str)
+
+ def __init__(
+ self,
+ calibration_videos_folder_path: Union[str, Path],
+ charuco_square_size_mm: Union[int, float],
+ ):
+ super().__init__()
+ self._charuco_square_size_mm = charuco_square_size_mm
+ self._calibration_videos_folder_path = calibration_videos_folder_path
+
+ def _emit_in_progress_data(self, message: str):
+ self.in_progress.emit(message)
+
+ def run(self):
+ logger.info(
+ "Beginning Anipose calibration with Charuco Square Size (mm): {}".format(
+ self._charuco_square_size_mm
+ )
+ )
+
+ try:
+ run_anipose_capture_volume_calibration(
+ charuco_square_size=self._charuco_square_size_mm,
+ calibration_videos_folder_path=self._calibration_videos_folder_path,
+ pin_camera_0_to_origin=True,
+ progress_callback=self._emit_in_progress_data,
+ )
+ except:
+ logger.error("something failed in the anipose calibration")
+ raise Exception
+
+ logger.info("Anipose calibration complete")
+
+ self.finished.emit()
diff --git a/src/gui/main/workers/cam_charuco_frame_thread_worker.py b/src/gui/main/workers/cam_charuco_frame_thread_worker.py
new file mode 100644
index 00000000..298b8996
--- /dev/null
+++ b/src/gui/main/workers/cam_charuco_frame_thread_worker.py
@@ -0,0 +1,93 @@
+from typing import Union, List
+
+import cv2
+from PyQt6.QtCore import QThread, Qt, pyqtSignal
+from PyQt6.QtGui import QImage
+
+from src.cameras.capture.dataclasses.frame_payload import FramePayload
+from src.cameras.capture.opencv_camera.opencv_camera import OpenCVCamera
+from src.cameras.persistence.video_writer.video_recorder import VideoRecorder
+from src.config.webcam_config import WebcamConfig
+from src.pipelines.calibration_pipeline.charuco_board_detection.charuco_board_detector import (
+ CharucoBoardDetector,
+)
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class CamCharucoFrameThreadWorker(QThread):
+ image_updated_signal = pyqtSignal(QImage)
+ ready_to_save_to_video = pyqtSignal(VideoRecorder)
+
+ def __init__(self, webcam_config: WebcamConfig):
+ super().__init__()
+ self._charuco_board_detector = CharucoBoardDetector()
+ self._video_recorder = VideoRecorder()
+ self._webcam_config = webcam_config
+ self._should_save_frames = False
+ self._should_continue = True
+ self._saved_frame_list = []
+
+ @property
+ def should_save_frames(self):
+ return self._should_save_frames
+
+ @property
+ def video_recorder(self):
+ return self._video_recorder
+
+ def start_saving_frames(self):
+ self._should_save_frames = True
+
+ def stop_saving_frames(self):
+ self._should_save_frames = False
+
+ def reset_video_recorder(self):
+ self._video_recorder = VideoRecorder()
+
+ def run(self):
+
+ open_cv_camera = OpenCVCamera(self._webcam_config)
+ open_cv_camera.connect()
+ open_cv_camera.start_frame_capture_thread()
+
+ self._open_cv_camera = open_cv_camera
+ self._should_continue = True
+ any_frames_recorded = False
+ try:
+ while open_cv_camera.is_capturing_frames and self._should_continue:
+ if not open_cv_camera.new_frame_ready:
+ continue
+ frame_payload = open_cv_camera.latest_frame
+
+ if self._should_save_frames:
+ any_frames_recorded = True
+ print("saving frame :D")
+ self._video_recorder.append_frame_payload_to_list(frame_payload)
+
+ charuco_payload = (
+ self._charuco_board_detector.detect_charuco_board_in_frame_payload(
+ frame_payload
+ )
+ )
+ image_to_display = charuco_payload.annotated_image
+ image_to_display = cv2.flip(image_to_display, 1)
+ image_to_display = cv2.cvtColor(image_to_display, cv2.COLOR_BGR2RGB)
+ converted_frame = QImage(
+ image_to_display.data,
+ image_to_display.shape[1],
+ image_to_display.shape[0],
+ QImage.Format.Format_RGB888,
+ )
+ converted_frame = converted_frame.scaledToHeight(300)
+
+ self.image_updated_signal.emit(converted_frame)
+ finally:
+ logger.info(f"Closing Camera {self._open_cv_camera.webcam_id_as_str}")
+ self._open_cv_camera.close()
+
+ def quit(self):
+ self._open_cv_camera.close()
+ super().quit()
diff --git a/src/gui/main/workers/cam_detection_thread_worker.py b/src/gui/main/workers/cam_detection_thread_worker.py
new file mode 100644
index 00000000..81934181
--- /dev/null
+++ b/src/gui/main/workers/cam_detection_thread_worker.py
@@ -0,0 +1,18 @@
+from PyQt6.QtCore import QThread, pyqtSignal
+
+from src.cameras.detection.cam_singleton import get_or_create_cams
+from src.cameras.detection.models import FoundCamerasResponse
+
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class CameraDetectionThreadWorker(QThread):
+ finished = pyqtSignal(FoundCamerasResponse)
+
+ def run(self):
+ logger.info("Detecting cameras....")
+ found_cameras_response = get_or_create_cams(always_create=True)
+ logger.info(f"Cameras detected: {found_cameras_response}")
+ self.finished.emit(found_cameras_response)
diff --git a/src/gui/main/workers/mediapipe_2d_detection_thread_worker.py b/src/gui/main/workers/mediapipe_2d_detection_thread_worker.py
new file mode 100644
index 00000000..a592ff86
--- /dev/null
+++ b/src/gui/main/workers/mediapipe_2d_detection_thread_worker.py
@@ -0,0 +1,35 @@
+from pathlib import Path
+from typing import Union, List
+
+from PyQt6.QtCore import QThread, pyqtSignal
+
+
+import logging
+
+from src.core_processes.mediapipe_2d_skeleton_detector.mediapipe_skeleton_detector import (
+ MediaPipeSkeletonDetector,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class Mediapipe2dDetectionThreadWorker(QThread):
+ finished = pyqtSignal()
+
+ def __init__(
+ self,
+ path_to_folder_of_videos_to_process: Union[str, Path],
+ output_data_folder_path: Union[str, Path],
+ ):
+ super().__init__()
+ self._path_to_folder_of_videos_to_process = path_to_folder_of_videos_to_process
+ self._output_data_folder_path = output_data_folder_path
+
+ def run(self):
+ logger.info(f"tracking 2D mediapipe skeletons in videos ")
+ mediapipe_skeleton_detector = MediaPipeSkeletonDetector()
+ mediapipe_skeleton_detector.process_folder_full_of_videos(
+ self._path_to_folder_of_videos_to_process, self._output_data_folder_path
+ )
+
+ self.finished.emit()
diff --git a/src/gui/main/workers/save_to_video_thread_worker.py b/src/gui/main/workers/save_to_video_thread_worker.py
new file mode 100644
index 00000000..5a489468
--- /dev/null
+++ b/src/gui/main/workers/save_to_video_thread_worker.py
@@ -0,0 +1,26 @@
+import logging
+from pathlib import Path
+from typing import Union, Dict
+
+from PyQt6.QtCore import QThread
+
+from src.cameras.persistence.video_writer.video_recorder import VideoRecorder
+from src.cameras.save_synchronized_videos import save_synchronized_videos
+
+logger = logging.getLogger(__name__)
+
+
+class SaveToVideoThreadWorker(QThread):
+ def __init__(
+ self,
+ dictionary_of_video_recorders: Dict[str, VideoRecorder],
+ folder_to_save_videos: Union[str, Path],
+ ):
+ super().__init__()
+ self._dictionary_of_video_recorders = dictionary_of_video_recorders
+ self._folder_to_save_videos = folder_to_save_videos
+
+ def run(self):
+ save_synchronized_videos(
+ self._dictionary_of_video_recorders, self._folder_to_save_videos
+ )
diff --git a/src/gui/main/workers/thread_worker_manager.py b/src/gui/main/workers/thread_worker_manager.py
new file mode 100644
index 00000000..4ee61dd1
--- /dev/null
+++ b/src/gui/main/workers/thread_worker_manager.py
@@ -0,0 +1,140 @@
+from pathlib import Path
+from typing import Dict, Union
+
+import numpy as np
+from PyQt6.QtCore import pyqtSignal
+from PyQt6.QtWidgets import QWidget, QVBoxLayout, QLabel
+
+from src.cameras.detection.models import FoundCamerasResponse
+from src.config.webcam_config import WebcamConfig
+
+from src.gui.main.custom_widgets.single_camera_widget import CameraWidget
+from src.gui.main.workers.anipose_calibration_thread_worker import (
+ AniposeCalibrationThreadWorker,
+)
+from src.gui.main.workers.cam_detection_thread_worker import CameraDetectionThreadWorker
+
+import logging
+
+from src.gui.main.workers.mediapipe_2d_detection_thread_worker import (
+ Mediapipe2dDetectionThreadWorker,
+)
+from src.gui.main.workers.save_to_video_thread_worker import SaveToVideoThreadWorker
+from src.gui.main.workers.triangulate_3d_data_thread_worker import (
+ Triangulate3dDataThreadWorker,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class ThreadWorkerManager(QWidget):
+ """This guy's job is to hold on to the parts of threads that need to be kept alive while they are running"""
+
+ camera_detection_finished = pyqtSignal(FoundCamerasResponse)
+ cameras_connected_signal = pyqtSignal(dict)
+
+ def __init__(self):
+ super().__init__()
+
+ def launch_detect_cameras_worker(self):
+ logger.info("Launch camera detection worker")
+ self._camera_detection_thread_worker = CameraDetectionThreadWorker()
+ self._camera_detection_thread_worker.finished.connect(
+ self.camera_detection_finished.emit
+ )
+ self._camera_detection_thread_worker.start()
+
+ def create_camera_widgets_with_running_threads(
+ self, dictionary_of_webcam_configs=Dict[str, WebcamConfig]
+ ):
+ logger.info("creating camera widgets with running threads")
+
+ self._camera_widgets = []
+ dictionary_of_single_camera_layouts = {}
+ for webcam_config in dictionary_of_webcam_configs.values():
+ camera_widget = CameraWidget(webcam_config)
+ camera_widget.start()
+
+ camera_layout = QVBoxLayout()
+ camera_layout.addWidget(QLabel(f"Camera {str(webcam_config.webcam_id)}"))
+ camera_layout.addWidget(camera_widget)
+
+ dictionary_of_single_camera_layouts[webcam_config.webcam_id] = camera_layout
+
+ self._camera_widgets.append(camera_widget)
+
+ self.cameras_connected_signal.emit(dictionary_of_single_camera_layouts)
+
+ def start_recording_videos(self):
+ logger.info("starting to save frames in camera streams for later recording")
+ for camera_widget in self._camera_widgets:
+ camera_widget.start_saving_frames()
+
+ def stop_recording_videos(self):
+ logger.info("stopping saving frames in camera streams")
+ for camera_widget in self._camera_widgets:
+ camera_widget.stop_saving_frames()
+
+ def launch_save_videos_thread_worker(
+ self, folder_to_save_videos: [Union[str, Path]]
+ ):
+ logger.info("Launching save videos thread worker...")
+
+ dictionary_of_video_recorders = {}
+ for camera_widget in self._camera_widgets:
+ dictionary_of_video_recorders[
+ str(camera_widget.camera_id)
+ ] = camera_widget.video_recorder
+
+ self._save_to_video_thread_worker = SaveToVideoThreadWorker(
+ dictionary_of_video_recorders=dictionary_of_video_recorders,
+ folder_to_save_videos=folder_to_save_videos,
+ )
+ self._save_to_video_thread_worker.start()
+ self._save_to_video_thread_worker.finished.connect(self._reset_video_recorders)
+
+ def _reset_video_recorders(self):
+ for camera_widget in self._camera_widgets:
+ camera_widget.reset_video_recorder()
+
+ def launch_anipose_calibration_thread_worker(
+ self,
+ calibration_videos_folder_path: Union[str, Path],
+ charuco_square_size_mm: float,
+ ):
+ self._anipose_calibration_worker = AniposeCalibrationThreadWorker(
+ calibration_videos_folder_path=calibration_videos_folder_path,
+ charuco_square_size_mm=charuco_square_size_mm,
+ )
+ self._anipose_calibration_worker.start()
+ self._anipose_calibration_worker.in_progress.connect(print)
+
+ def launch_detect_2d_skeletons_thread_worker(
+ self,
+ synchronized_videos_folder_path: Union[str, Path],
+ output_data_folder_path: Union[str, Path],
+ ):
+ logger.info("Launching mediapipe 2d skeleton thread worker...")
+
+ self._mediapipe_2d_detection_thread_worker = Mediapipe2dDetectionThreadWorker(
+ path_to_folder_of_videos_to_process=synchronized_videos_folder_path,
+ output_data_folder_path=output_data_folder_path,
+ )
+
+ self._mediapipe_2d_detection_thread_worker.start()
+
+ def launch_triangulate_3d_data_thread_worker(
+ self,
+ anipose_calibration_object,
+ mediapipe_2d_data: np.ndarray,
+ output_data_folder_path: Union[str, Path],
+ ):
+ logger.info("Launching Triangulate 3d data thread worker...")
+
+ self._triangulate_3d_data_thread_worker = Triangulate3dDataThreadWorker(
+ anipose_calibration_object=anipose_calibration_object,
+ mediapipe_2d_data=mediapipe_2d_data,
+ output_data_folder_path=output_data_folder_path,
+ )
+
+ self._triangulate_3d_data_thread_worker.start()
diff --git a/src/gui/main/workers/triangulate_3d_data_thread_worker.py b/src/gui/main/workers/triangulate_3d_data_thread_worker.py
new file mode 100644
index 00000000..943cea62
--- /dev/null
+++ b/src/gui/main/workers/triangulate_3d_data_thread_worker.py
@@ -0,0 +1,41 @@
+from pathlib import Path
+from typing import Union
+
+import numpy as np
+from PyQt6.QtCore import QThread, pyqtSignal
+
+import logging
+
+from src.core_processes.capture_volume_calibration.triangulate_3d_data import (
+ triangulate_3d_data,
+)
+
+logger = logging.getLogger(__name__)
+
+
+class Triangulate3dDataThreadWorker(QThread):
+ finished = pyqtSignal()
+
+ def __init__(
+ self,
+ anipose_calibration_object,
+ mediapipe_2d_data: np.ndarray,
+ output_data_folder_path: Union[str, Path],
+ ):
+ super().__init__()
+ self._anipose_calibration_object = anipose_calibration_object
+ self._mediapipe_2d_data = mediapipe_2d_data
+ self._output_data_folder_path = output_data_folder_path
+
+ def run(self):
+ logger.info(
+ f"Triangulating 3d data (i.e. combining 2d skeleton data with camera calibration data to estimate 3d positions of tracked points"
+ )
+
+ triangulate_3d_data(
+ anipose_calibration_object=self._anipose_calibration_object,
+ mediapipe_2d_data=self._mediapipe_2d_data,
+ output_data_folder_path=self._output_data_folder_path,
+ )
+
+ self.finished.emit()
diff --git a/src/log/config.py b/src/log/config.py
index 3d7db6d2..fafddd77 100644
--- a/src/log/config.py
+++ b/src/log/config.py
@@ -3,7 +3,6 @@ import logging.handlers
import sys
from logging.config import dictConfig
-
DEFAULT_LOGGING = {"version": 1, "disable_existing_loggers": False}
diff --git a/src/pipelines/calibration_pipeline/anipose_camera_calibration/anipose_camera_calibration.py b/src/pipelines/calibration_pipeline/anipose_camera_calibration/anipose_camera_calibration.py
index 9556cc87..dd42c026 100644
--- a/src/pipelines/calibration_pipeline/anipose_camera_calibration/anipose_camera_calibration.py
+++ b/src/pipelines/calibration_pipeline/anipose_camera_calibration/anipose_camera_calibration.py
@@ -3,13 +3,9 @@ from pathlib import Path
from typing import Union
import numpy as np
-from cv2 import aruco_CharucoBoard
-from scipy.spatial.transform import Rotation
from src.config.home_dir import (
- get_session_folder_path,
get_freemocap_data_folder_path,
- get_calibration_videos_folder_path,
)
from src.pipelines.calibration_pipeline.anipose_camera_calibration import (
freemocap_anipose,
@@ -26,12 +22,11 @@ logger = logging.getLogger(__name__)
class AniposeCameraCalibrator:
def __init__(
self,
- session_id: str,
charuco_board_object: CharucoBoardDataClass,
- charuco_square_size: Union[int, float] = 1,
+ charuco_square_size: Union[int, float],
+ calibration_videos_folder_path: Union[str, Path],
):
- self._session_id = session_id
self._charuco_board_object = charuco_board_object
if charuco_square_size == 1:
@@ -39,27 +34,28 @@ class AniposeCameraCalibrator:
"Charuco square size is not set, so units of 3d reconstructed data will be in units of `however_long_the_black_edge_of_the_charuco_square_was`. Please input `charuco_square_size` in millimeters (or your preferred unity of length)"
)
self._charuco_square_size = charuco_square_size
- self.get_paths_and_whatnot()
- self.initialize_anipose_objects()
+ self._calibration_videos_folder_path = calibration_videos_folder_path
+ self._session_folder_path = Path(self._calibration_videos_folder_path).parent
+ self._get_video_paths()
+ self._initialize_anipose_objects()
- def get_paths_and_whatnot(self):
- self.session_folder_path = Path(get_session_folder_path(self._session_id))
- calibration_videos_folder = Path(
- get_calibration_videos_folder_path(self._session_id)
- )
+ def _get_video_paths(
+ self,
+ ):
self._list_of_video_paths = [
this_video_path
- for this_video_path in calibration_videos_folder.glob("*.mp4".lower())
+ for this_video_path in Path(self._calibration_videos_folder_path).glob(
+ "*.mp4".lower()
+ )
]
- def initialize_anipose_objects(self):
+ def _initialize_anipose_objects(self):
list_of_camera_names = [
this_video_path.stem for this_video_path in self._list_of_video_paths
]
self._anipose_camera_group_object = freemocap_anipose.CameraGroup.from_names(
list_of_camera_names
)
- self._anipose_camera_group_object.metadata["session_id"] = self._session_id
self._anipose_camera_group_object.metadata[
"charuco_square_size"
] = self._charuco_square_size
@@ -100,9 +96,9 @@ class AniposeCameraCalibrator:
# self._anipose_camera_group_object = self.rotate_cameras_so_camera_zero_aligns_with_XYZ(self._anipose_camera_group_object)
# save calibration info to files
- calibration_toml_filename = f"{self._session_id}_camera_calibration.toml"
+ calibration_toml_filename = f"camera_calibration_data.toml"
camera_calibration_toml_path = (
- self.session_folder_path / calibration_toml_filename
+ self._session_folder_path / calibration_toml_filename
)
self._anipose_camera_group_object.dump(camera_calibration_toml_path)
@@ -166,7 +162,3 @@ class AniposeCameraCalibrator:
# original_translation_vectors]
# _anipose_camera_group_object.set_rotations(rotated_translation_vectors)
# return _anipose_camera_group_object
-
-
-if __name__ == "__main__":
- pass
diff --git a/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.py b/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.py
index bf2f081a..d5e30257 100644
--- a/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.py
+++ b/src/pipelines/calibration_pipeline/anipose_camera_calibration/freemocap_anipose.py
@@ -24,7 +24,7 @@ from aniposelib.boards import (
from aniposelib.utils import get_initial_extrinsics, make_M, get_rtvec, get_connections
numba_logger = logging.getLogger("numba")
-numba_logger.setLevel(logging.WARNING)
+numba_logger.setLevel(logging.DEBUG)
@jit(nopython=True, parallel=True)
diff --git a/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py b/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py
index 2af920c0..ffc2922d 100644
--- a/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py
+++ b/src/pipelines/calibration_pipeline/calibration_pipeline_orchestrator.py
@@ -2,21 +2,21 @@ import time
import logging
import traceback
from pathlib import Path
-from typing import Union
+from typing import Union, Callable
import cv2
from src.cameras.multicam_manager.cv_camera_manager import OpenCVCameraManager
from src.config.home_dir import (
- create_session_id,
+ create_default_session_id,
get_session_folder_path,
get_freemocap_data_folder_path,
- get_session_output_data_folder_path,
- get_session_calibration_file_path,
+ get_output_data_folder_path,
+ get_session_calibration_toml_file_path,
)
-from src.core_processor.timestamp_manager.timestamp_manager import TimestampManager
-from src.core_processor.show_cam_window import show_cam_window
-from src.core_processor.utils.image_fps_writer import write_fps_to_image
+from src.core_processes.timestamp_manager.timestamp_manager import TimestampManager
+from src.core_processes.show_cam_window import show_cam_window
+from src.core_processes.utils.image_fps_writer import write_fps_to_image
from src.pipelines.calibration_pipeline.anipose_camera_calibration import (
freemocap_anipose,
)
@@ -39,7 +39,7 @@ class CalibrationPipelineOrchestrator:
):
if session_id is None:
- self._session_id = create_session_id(
+ self._session_id = create_default_session_id(
string_tag="calibration"
) # create a 'calibration only' session
else:
@@ -119,10 +119,8 @@ class CalibrationPipelineOrchestrator:
)
# detect charuco board
- this_charuco_frame_payload = (
- self._charuco_board_detector.detect_charuco_board(
- this_cam_latest_frame
- )
+ this_charuco_frame_payload = self._charuco_board_detector.detect_charuco_board_in_frame_payload(
+ this_cam_latest_frame
)
if show_camera_views_in_windows:
@@ -172,12 +170,14 @@ class CalibrationPipelineOrchestrator:
self,
charuco_square_size: Union[int, float] = 1,
pin_camera_0_to_origin: bool = False,
+ progress_callback: Callable[[str], None] = None,
):
anipose_camera_calibrator = AniposeCameraCalibrator(
self.session_id,
self._charuco_board_detector.charuco_board_data_class_object,
charuco_square_size=charuco_square_size,
)
+ progress_callback("Endurance is great wow wow wow")
return anipose_camera_calibrator.calibrate_camera_capture_volume(
pin_camera_0_to_origin=pin_camera_0_to_origin
)
@@ -192,7 +192,9 @@ class CalibrationPipelineOrchestrator:
return freemocap_anipose.CameraGroup.load(str(last_successful_calibration_path))
def load_calibration_from_session_id(self, session_id: str):
- session_calibration_file_path = get_session_calibration_file_path(session_id)
+ session_calibration_file_path = get_session_calibration_toml_file_path(
+ session_id
+ )
logger.info(
f"loading camera calibration file from:{str(session_calibration_file_path)}"
)
@@ -209,7 +211,7 @@ if __name__ == "__main__":
record_new = True
if record_new:
- session_id = create_session_id("calibration")
+ session_id = create_default_session_id("calibration")
session_path = Path(get_session_folder_path(session_id))
logger.info(
f"Creating `calibration only` session folder at: {str(session_path)}"
diff --git a/src/pipelines/calibration_pipeline/charuco_board_detection/charuco_board_detector.py b/src/pipelines/calibration_pipeline/charuco_board_detection/charuco_board_detector.py
index d5ec696e..5af0e9ad 100644
--- a/src/pipelines/calibration_pipeline/charuco_board_detection/charuco_board_detector.py
+++ b/src/pipelines/calibration_pipeline/charuco_board_detection/charuco_board_detector.py
@@ -1,5 +1,5 @@
import logging
-from typing import Dict
+from typing import Dict, List
import cv2
import numpy as np
@@ -33,7 +33,7 @@ class CharucoBoardDetector:
self.charuco_board_data_class_object.number_of_charuco_corners
)
- def detect_charuco_board(
+ def detect_charuco_board_in_frame_payload(
self, raw_frame_payload: FramePayload
) -> CharucoFramePayload:
@@ -77,7 +77,7 @@ class CharucoBoardDetector:
termination_criteria_threshold = (
cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER,
100,
- 0.00001,
+ 0.0001,
)
grayscale_image = cv2.cvtColor(raw_image, cv2.COLOR_BGR2GRAY)
@@ -137,9 +137,9 @@ class CharucoBoardDetector:
image_height=image_height,
)
- def format_charuco2d_data(self, this_multi_frame_charuco_data) -> Dict:
+ def format_charuco2d_data(self, this_multi_frame_charuco_data_list: List) -> Dict:
- number_of_tracked_points = this_multi_frame_charuco_data[
+ number_of_tracked_points = this_multi_frame_charuco_data_list[
0
].charuco_view_data.charuco_board_object.number_of_charuco_corners
@@ -148,7 +148,7 @@ class CharucoBoardDetector:
(number_of_tracked_points, 2)
)
base_charuco_data_npy_with_nans_for_missing_data_xy[:] = np.nan
- for this_cam_data in this_multi_frame_charuco_data:
+ for this_cam_data in this_multi_frame_charuco_data_list:
if this_cam_data.charuco_view_data.some_charuco_corners_found:
this_frame_charuco_data_xy = (
base_charuco_data_npy_with_nans_for_missing_data_xy.copy()
@@ -172,5 +172,5 @@ class CharucoBoardDetector:
if __name__ == "__main__":
pass
# ## Jon, Run me to easily start a charuco board detect run
- # print('starting main')
+ # print('starting icis_conference_main')
# BoardDetection().process()
diff --git a/src/pipelines/session_pipeline/session_pipeline_orchestrator.py b/src/pipelines/session_pipeline/session_pipeline_orchestrator.py
index 9fd2b37e..baa914cd 100644
--- a/src/pipelines/session_pipeline/session_pipeline_orchestrator.py
+++ b/src/pipelines/session_pipeline/session_pipeline_orchestrator.py
@@ -11,17 +11,17 @@ from src.cameras.persistence.video_writer.save_options_dataclass import SaveOpti
from src.config.data_paths import freemocap_data_path
from src.config.home_dir import (
create_session_folder,
- create_session_id,
+ create_default_session_id,
get_most_recent_session_id,
- get_session_output_data_folder_path,
+ get_output_data_folder_path,
)
-from src.core_processor.mediapipe_skeleton_detector.mediapipe_skeleton_detector import (
+from src.core_processes.mediapipe_2d_skeleton_detector.mediapipe_skeleton_detector import (
MediaPipeSkeletonDetector,
Mediapipe2dDataPayload,
)
-from src.core_processor.show_cam_window import show_cam_window
-from src.core_processor.timestamp_manager.timestamp_manager import TimestampManager
-from src.core_processor.utils.image_fps_writer import write_fps_to_image
+from src.core_processes.show_cam_window import show_cam_window
+from src.core_processes.timestamp_manager.timestamp_manager import TimestampManager
+from src.core_processes.utils.image_fps_writer import write_fps_to_image
from src.pipelines.calibration_pipeline.calibration_pipeline_orchestrator import (
CalibrationPipelineOrchestrator,
)
@@ -51,7 +51,7 @@ class SessionPipelineOrchestrator:
if session_id is not None:
self._session_id = session_id
else:
- self._session_id = create_session_id()
+ self._session_id = create_default_session_id()
self._expected_framerate = expected_framerate
@@ -259,10 +259,8 @@ class SessionPipelineOrchestrator:
if detect_charuco:
# detect charuco board
- this_charuco_frame_payload = (
- self._charuco_board_detector.detect_charuco_board(
- this_cam_latest_frame
- )
+ this_charuco_frame_payload = self._charuco_board_detector.detect_charuco_board_in_frame_payload(
+ this_cam_latest_frame
)
image_to_display = (
this_charuco_frame_payload.annotated_image
@@ -566,7 +564,7 @@ class SessionPipelineOrchestrator:
)
)
- self._save_mediapipe3d_data_to_npy(
+ path_to_3d_data_npy = self._save_mediapipe3d_data_to_npy(
data3d_numFrames_numTrackedPoints_XYZ,
data3d_numFrames_numTrackedPoints_reprojectionError,
)
@@ -576,12 +574,14 @@ class SessionPipelineOrchestrator:
data3d_numFrames_numTrackedPoint_reprojectionError=data3d_numFrames_numTrackedPoints_reprojectionError,
)
+ return path_to_3d_data_npy
+
def _save_mediapipe3d_data_to_npy(
self,
data3d_numFrames_numTrackedPoints_XYZ: np.ndarray,
data3d_numFrames_numTrackedPoints_reprojectionError: np.ndarray,
):
- output_data_folder = Path(get_session_output_data_folder_path(self._session_id))
+ output_data_folder = Path(get_output_data_folder_path(self._session_id))
# save spatial XYZ data
self._mediapipe_3dData_save_path = (
@@ -604,6 +604,8 @@ class SessionPipelineOrchestrator:
data3d_numFrames_numTrackedPoints_reprojectionError,
)
+ return str(self._mediapipe_3dData_save_path)
+
def _threshold_2d_data_by_confidence(
self,
mediapipe2d_data_payload: Mediapipe2dDataPayload,
@@ -615,7 +617,7 @@ class SessionPipelineOrchestrator:
def load_mediapipe3d_skeleton_data(session_id: str = None):
if session_id is None:
session_id = get_most_recent_session_id()
- output_data_folder = Path(get_session_output_data_folder_path(session_id))
+ output_data_folder = Path(get_output_data_folder_path(session_id))
mediapipe3d_xyz_file_path = (
output_data_folder
/ "mediapipe_3dData_numFrames_numTrackedPoints_spatialXYZ.npy"
@@ -640,23 +642,6 @@ def load_mediapipe3d_skeleton_data(session_id: str = None):
)
-def load_mediapipe2d_data(session_id: str = None):
- if session_id is None:
- session_id = get_most_recent_session_id()
- output_data_folder = Path(get_session_output_data_folder_path(session_id))
- mediapipe2d_xy_file_path = (
- output_data_folder
- / "mediapipe_2dData_numCams_numFrames_numTrackedPoints_pixelXY.npy"
- )
- logger.info(f"loading: {mediapipe2d_xy_file_path}")
- mediapipe2d_numCams_numFrames_numTrackedPoints_pixelXY = np.load(
- mediapipe2d_xy_file_path
- )
- # TODO - create a dataclass for 2d mediapipe data, including things split up by body, hands,
- # and face (and maybe the raw `mediapipe results` data things if that's not too much data)
- return mediapipe2d_numCams_numFrames_numTrackedPoints_pixelXY
-
-
if __name__ == "__main__":
print("running `session_pipeline_orchestrator` as `__main__")
diff --git a/src/qt_visualizer_and_gui/qt_visualizer_and_gui.py b/src/qt_visualizer_and_gui/qt_visualizer_and_gui.py
index 47415c39..a82ecc84 100644
--- a/src/qt_visualizer_and_gui/qt_visualizer_and_gui.py
+++ b/src/qt_visualizer_and_gui/qt_visualizer_and_gui.py
@@ -11,7 +11,7 @@ from pyqtgraph.dockarea.DockArea import DockArea
from pyqtgraph.Qt import QtWidgets
from mediapipe.python.solutions import holistic as mp_holistic
-from src.core_processor.timestamp_manager.timestamp_manager import TimestampManager
+from src.core_processes.timestamp_manager.timestamp_manager import TimestampManager
from src.pipelines.session_pipeline.data_classes.data_3d_single_frame_payload import (
Data3dMultiFramePayload,
)
@@ -84,7 +84,7 @@ class QTVisualizerAndGui:
def _setup_main_window(self, window_width: int = 1000, window_height: int = 1000):
"""
- This is the main main window for the GUI.
+ This is the icis_conference_main icis_conference_main window for the GUI.
Its structure is based loosely on the 'Dock Widgets' example from `python -m pyqtgraph.examples`
"""
self._main_window_widget = QtWidgets.QMainWindow()
diff --git a/versioneer.py b/versioneer.py
index 958cc008..db3a7aca 100644
--- a/versioneer.py
+++ b/versioneer.py
@@ -92,7 +92,7 @@ See [INSTALL.md](./INSTALL.md) for detailed installation instructions.
## Version-String Flavors
Code which uses Versioneer can learn about its version string at runtime by
-importing `_version` from your main `__init__.py` file and running the
+importing `_version` from your icis_conference_main `__init__.py` file and running the
`get_versions()` function. From the "outside" (e.g. in `setup.py`), you can
import the top-level `versioneer.py` and run `get_versions()`.
@@ -178,7 +178,7 @@ two common reasons why `setup.py` might not be in the root:
"master" and "slave" subprojects, each with their own `setup.py`,
`setup.cfg`, and `tox.ini`. Projects like these produce multiple PyPI
distributions (and upload multiple independently-installable tarballs).
-* Source trees whose main purpose is to contain a C library, but which also
+* Source trees whose icis_conference_main purpose is to contain a C library, but which also
provide bindings to Python (and perhaps other langauges) in subdirectories.
Versioneer will look for `.git` in parent directories, and most operations
@@ -1529,9 +1529,9 @@ def get_cmdclass():
if "versioneer" in sys.modules:
del sys.modules["versioneer"]
# this fixes the "python setup.py develop" case (also 'install' and
- # 'easy_install .'), in which subdependencies of the main project are
+ # 'easy_install .'), in which subdependencies of the icis_conference_main project are
# built (using setup.py bdist_egg) in the same python process. Assume
- # a main project A and a dependency B, which use different versions
+ # a icis_conference_main project A and a dependency B, which use different versions
# of Versioneer. A's setup.py imports A's Versioneer, leaving it in
# sys.modules by the time B's setup.py is executed, causing B to run
# with the wrong versioneer. Setuptools wraps the sub-dep builds in a