Free Motion Capture for Everyone πβ¨
TypeScript
End to end testing (#375)
philipqueen6fe040708bba
diff --git a/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.py b/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.pyindex 1f327a1e..239fdf2a 100644--- a/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.py+++ b/freemocap/core_processes/export_data/blender_stuff/get_best_guess_of_blender_path.py@@ -17,7 +17,7 @@ def guess_blender_exe_path_from_path(base_path: Union[str, Path]) -> Path:def get_best_guess_of_blender_path():if platform.system() == "Windows":- base_path = Path("C:\Program Files\Blender Foundation")+ base_path = Path(r"C:\Program Files\Blender Foundation")blender_exe_path = guess_blender_exe_path_from_path(base_path)if blender_exe_path is not None:diff --git a/freemocap/core_processes/post_process_skeleton_data/gap_fill_filter_and_origin_align_skeleton_data.py b/freemocap/core_processes/post_process_skeleton_data/gap_fill_filter_and_origin_align_skeleton_data.pyindex b2305aad..3ae39066 100644--- a/freemocap/core_processes/post_process_skeleton_data/gap_fill_filter_and_origin_align_skeleton_data.py+++ b/freemocap/core_processes/post_process_skeleton_data/gap_fill_filter_and_origin_align_skeleton_data.py@@ -496,7 +496,7 @@ def rotate_align_skeleton(assert (original_z_vector_length - rotated_up_vector_length < 1- ), f"Rotating the skeleton up vector changed its size -\ something went wrong (original_z_vector_length {original_z_vector_length} - rotated_up_vector_length {rotated_up_vector_length} = {original_z_vector_length - rotated_up_vector_length})"+ ), f"Rotating the skeleton up vector changed its size - something went wrong (original_z_vector_length {original_z_vector_length} - rotated_up_vector_length {rotated_up_vector_length} = {original_z_vector_length - rotated_up_vector_length})"skeleton_left_vector_rotated = positive_x_reference_vector_on_the_skeleton @ skeleton_inverse_rotation_matrixdiff --git a/freemocap/core_processes/process_motion_capture_videos/process_recording_folder.py b/freemocap/core_processes/process_motion_capture_videos/process_recording_folder.pyindex 99bbb084..3988f51e 100644--- a/freemocap/core_processes/process_motion_capture_videos/process_recording_folder.py+++ b/freemocap/core_processes/process_motion_capture_videos/process_recording_folder.py@@ -35,10 +35,10 @@ from freemocap.core_processes.post_process_skeleton_data.gap_fill_filter_and_ori)from freemocap.parameter_info_models.recording_processing_parameter_models import RecordingProcessingParameterModel-from freemocap.tests.test_mediapipe_2d_data_shape import (- test_mediapipe_2d_data_shape,+from freemocap.tests.test_image_tracking_data_shape import (+ test_image_tracking_data_shape,)-from freemocap.tests.test_mediapipe_3d_data_shape import test_mediapipe_3d_data_shape+from freemocap.tests.test_mediapipe_skeleton_data_shape import test_mediapipe_skeleton_data_shapefrom freemocap.utilities.rotate_by_90_degrees_around_x_axis import rotate_by_90_degrees_around_x_axisfrom freemocap.utilities.save_dictionary_to_json import save_dictionary_to_json@@ -88,10 +88,13 @@ def process_recording_folder(if kill_event is not None and kill_event.is_set():return- assert test_mediapipe_2d_data_shape(- synchronized_videos_folder=rec.recording_info_model.synchronized_videos_folder_path,- mediapipe_2d_data_file_path=rec.recording_info_model.mediapipe_2d_data_npy_file_path,- )+ try:+ assert test_image_tracking_data_shape(+ synchronized_video_folder_path=rec.recording_info_model.synchronized_videos_folder_path,+ image_tracking_data_file_name=rec.recording_info_model.mediapipe_2d_data_npy_file_path,+ )+ except AssertionError as error_message:+ logger.error(error_message)# spoof 3D data if single cameraif mediapipe_image_data_numCams_numFrames_numTrackedPts_XYZ.shape[0] == 1:@@ -126,11 +129,15 @@ def process_recording_folder(if kill_event is not None and kill_event.is_set():return- assert test_mediapipe_3d_data_shape(- synchronized_videos_folder=rec.recording_info_model.synchronized_videos_folder_path,- mediapipe_3d_data_npy_path=rec.recording_info_model.raw_mediapipe_3d_data_npy_file_path,- medipipe_reprojection_error_data_npy_path=rec.recording_info_model.mediapipe_reprojection_error_data_npy_file_path,- )+ try:+ assert test_mediapipe_skeleton_data_shape(+ synchronized_video_folder_path=rec.recording_info_model.synchronized_videos_folder_path,+ raw_skeleton_npy_file_path=rec.recording_info_model.raw_mediapipe_3d_data_npy_file_path,+ reprojection_error_file_name=rec.recording_info_model.mediapipe_reprojection_error_data_npy_file_path,+ )+ except AssertionError as error_message:+ logger.error(error_message)+#rotate so skeleton is closer to 'vertical' in a z-up reference framerotated_raw_skel3d_frame_marker_xyz = rotate_by_90_degrees_around_x_axis(raw_skel3d_frame_marker_xyz)@@ -148,12 +155,16 @@ def process_recording_folder(order=rec.post_processing_parameters_model.butterworth_filter_parameters.order,reference_frame_number=None,)-- assert test_mediapipe_3d_data_shape(- synchronized_videos_folder=rec.recording_info_model.synchronized_videos_folder_path,- mediapipe_3d_data_npy_path=rec.recording_info_model.mediapipe_3d_data_npy_file_path,- medipipe_reprojection_error_data_npy_path=rec.recording_info_model.mediapipe_reprojection_error_data_npy_file_path,- )++ try:+ test_mediapipe_skeleton_data_shape(+ synchronized_video_folder_path=rec.recording_info_model.synchronized_videos_folder_path,+ raw_skeleton_npy_file_path=rec.recording_info_model.mediapipe_3d_data_npy_file_path,+ reprojection_error_file_name=rec.recording_info_model.mediapipe_reprojection_error_data_npy_file_path,+ )+ except AssertionError as error_message:+ logger.error(error_message)+logger.info("Breaking up big `npy` into smaller bits and converting to `csv`...")# break up big NPY and save out csv'sdiff --git a/freemocap/parameter_info_models/recording_info_model.py b/freemocap/parameter_info_models/recording_info_model.pyindex 33908f94..b2d063e3 100644--- a/freemocap/parameter_info_models/recording_info_model.py+++ b/freemocap/parameter_info_models/recording_info_model.py@@ -18,8 +18,8 @@ from freemocap.system.paths_and_files_names import (ANNOTATED_VIDEOS_FOLDER_NAME,MEDIAPIPE_3D_NPY_FILE_NAME, create_camera_calibration_file_name,)-from freemocap.tests.test_mediapipe_2d_data_shape import test_mediapipe_2d_data_shape-from freemocap.tests.test_mediapipe_3d_data_shape import test_mediapipe_3d_data_shape+from freemocap.tests.test_image_tracking_data_shape import test_image_tracking_data_shape+from freemocap.tests.test_mediapipe_skeleton_data_shape import test_mediapipe_skeleton_data_shapefrom freemocap.tests.test_synchronized_video_frame_counts import (test_synchronized_video_frame_counts,)@@ -173,9 +173,9 @@ class RecordingFolderStatusChecker:def check_data2d_status(self) -> bool:try:- test_mediapipe_2d_data_shape(- synchronized_videos_folder=self.recording_info_model.synchronized_videos_folder_path,- mediapipe_2d_data_file_path=self.recording_info_model.mediapipe_2d_data_npy_file_path,+ test_image_tracking_data_shape(+ synchronized_video_folder_path=self.recording_info_model.synchronized_videos_folder_path,+ image_tracking_data_file_name=self.recording_info_model.mediapipe_2d_data_npy_file_path,)return True@@ -184,10 +184,10 @@ class RecordingFolderStatusChecker:def check_data3d_status(self) -> bool:try:- test_mediapipe_3d_data_shape(- synchronized_videos_folder=self.recording_info_model.synchronized_videos_folder_path,- mediapipe_3d_data_npy_path=self.recording_info_model.mediapipe_3d_data_npy_file_path,- medipipe_reprojection_error_data_npy_path=self.recording_info_model.mediapipe_reprojection_error_data_npy_file_path,+ test_mediapipe_skeleton_data_shape(+ synchronized_video_folder_path=self.recording_info_model.synchronized_videos_folder_path,+ raw_skeleton_npy_file_path=self.recording_info_model.mediapipe_3d_data_npy_file_path,+ reprojection_error_file_name=self.recording_info_model.mediapipe_reprojection_error_data_npy_file_path,)return Trueexcept AssertionError as e:@@ -197,8 +197,8 @@ class RecordingFolderStatusChecker:def check_center_of_mass_data_status(self) -> bool:try:test_total_body_center_of_mass_data_shape(- synchronized_videos_folder=self.recording_info_model.synchronized_videos_folder_path,- total_body_center_of_mass_npy_file_path=self.recording_info_model.total_body_center_of_mass_npy_file_path,+ synchronized_video_folder_path=self.recording_info_model.synchronized_videos_folder_path,+ total_body_center_of_mass_file_path=self.recording_info_model.total_body_center_of_mass_npy_file_path,)return Trueexcept AssertionError as e:diff --git a/freemocap/system/paths_and_files_names.py b/freemocap/system/paths_and_files_names.pyindex bf1d10a4..5081fa5c 100644--- a/freemocap/system/paths_and_files_names.py+++ b/freemocap/system/paths_and_files_names.py@@ -36,6 +36,10 @@ SEGMENT_CENTER_OF_MASS_NPY_FILE_NAME = "segmentCOM_frame_joint_xyz.npy"TOTAL_BODY_CENTER_OF_MASS_NPY_FILE_NAME = "total_body_center_of_mass_xyz.npy"+# Figshare info+FIGSHARE_ZIP_FILE_URL = "https://figshare.com/ndownloader/files/40293973"+FIGSHARE_SAMPLE_DATA_FILE_NAME = "freemocap_sample_data"+# logoPATH_TO_FREEMOCAP_LOGO_SVG = str(Path(freemocap.__file__).parent.parent / "assets/logo/freemocap-logo-black-border.svg")diff --git a/freemocap/tests/conftest.py b/freemocap/tests/conftest.pynew file mode 100644index 00000000..44d69db9--- /dev/null+++ b/freemocap/tests/conftest.py@@ -0,0 +1,55 @@+import pytest++from freemocap.tests.utilities.import_sample_data import (+ load_sample_data,+ find_data_folder_path,+ find_raw_skeleton_npy_file_name,+ find_synchronized_videos_folder_path,+ find_image_tracking_data_file_name,+ find_reprojection_error_file_name,+ find_total_body_center_of_mass_file_name,+)+from freemocap.tests.utilities.process_recording_headless import process_recording_headless, find_calibration_toml_path+++def pytest_sessionstart():+ pytest.sample_session_folder_path = load_sample_data()+ calibration_toml_path = find_calibration_toml_path(pytest.sample_session_folder_path)+ process_recording_headless(+ recording_path=pytest.sample_session_folder_path, path_to_camera_calibration_toml=calibration_toml_path+ )+++def sample_session_path():+ return pytest.sample_session_folder_path+++def synchronized_video_folder_path():+ return find_synchronized_videos_folder_path(pytest.sample_session_folder_path)+++def data_folder_path():+ return find_data_folder_path(pytest.sample_session_folder_path)+++def raw_skeleton_npy_file_path():+ return find_raw_skeleton_npy_file_name(find_data_folder_path(pytest.sample_session_folder_path))+++def total_body_center_of_mass_file_path():+ return find_total_body_center_of_mass_file_name(find_data_folder_path(pytest.sample_session_folder_path))+++def image_tracking_data_file_name():+ return find_image_tracking_data_file_name(find_data_folder_path(pytest.sample_session_folder_path))+++def reprojection_error_file_name():+ return find_reprojection_error_file_name(find_data_folder_path(pytest.sample_session_folder_path))diff --git a/freemocap/tests/test_image_tracking_data_shape.py b/freemocap/tests/test_image_tracking_data_shape.pynew file mode 100644index 00000000..1205f69f--- /dev/null+++ b/freemocap/tests/test_image_tracking_data_shape.py@@ -0,0 +1,48 @@+import pytest+import numpy as np+from pathlib import Path+from typing import Union++from freemocap.tests.utilities.get_number_of_frames_of_videos_in_a_folder import (+ get_number_of_frames_of_videos_in_a_folder,+)+from freemocap.utilities.get_video_paths import get_video_paths++[email protected]("synchronized_video_folder_path", "image_tracking_data_file_name")+def test_image_tracking_data_shape(+ synchronized_video_folder_path: Union[str, Path],+ image_tracking_data_file_name: Union[str, Path],+):+ """+ test that the `mediapipe 2d detection` process worked correctly by checking:++ 1. There is an `.npy` file containing the mediapipe 2d data in the `output_data_folder`+ 2. The dimensions of that `npy` (number of cameras, number of frames, [ need to do - number of tracked points], [pixelX, pixelY] matches the videos in the `synchronized videos` folder++ TODO - check number of tracked points vs 'expected' number of tracked points+ """++ assert Path(image_tracking_data_file_name).is_file(), f"{image_tracking_data_file_name} is not a file"++ image_tracking_data = np.load(image_tracking_data_file_name)++ list_of_video_paths = get_video_paths(Path(synchronized_video_folder_path))+ number_of_videos = len(list_of_video_paths)+ assert (+ image_tracking_data.shape[0] == number_of_videos+ ), f"Number of videos in {image_tracking_data_file_name} does not match number of videos in synchronized videos folder"++ frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path)++ assert (+ len(set(frame_count)) == 1+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"+ assert (+ image_tracking_data.shape[1] == frame_count[0]+ ), f"Number of frames in {image_tracking_data_file_name} does not match number of frames of videos in {synchronized_video_folder_path}"++ # TODO - check number of tracked points vs 'expected' number of tracked points++ assert image_tracking_data.shape[3] == 3, f"Data has {image_tracking_data.shape[3]} dimensions, expected 3 dimensions"+diff --git a/freemocap/tests/test_mediapipe_2d_data_shape.py b/freemocap/tests/test_mediapipe_2d_data_shape.pydeleted file mode 100644index ff45913a..00000000--- a/freemocap/tests/test_mediapipe_2d_data_shape.py+++ /dev/null@@ -1,49 +0,0 @@-from pathlib import Path-from typing import Union--import numpy as np--from freemocap.tests.utilities.get_number_of_frames_of_videos_in_a_folder import (- get_number_of_frames_of_videos_in_a_folder,-)-from freemocap.utilities.get_video_paths import get_video_paths---def test_mediapipe_2d_data_shape(- synchronized_videos_folder: Union[str, Path],- mediapipe_2d_data_file_path: Union[str, Path],-):-- """- test that the `mediapipe 2d detection` process worked correctly by checking:-- 1. There is an `.npy` file containing the mediapipe 2d data in the `output_data_folder`- 2. The dimensions of that `npy` (number of cameras, number of frames, [ need to do - number of tracked points], [pixelX, pixelY] matches the videos in the `synchronized videos` folder-- TODO - check number of tracked points vs 'expected' number of tracked points- """-- assert Path(- mediapipe_2d_data_file_path- ).is_file(), f"{mediapipe_2d_data_file_path} is not a file"-- mediapipe_2d_data = np.load(mediapipe_2d_data_file_path)-- list_of_video_paths = get_video_paths(Path(synchronized_videos_folder))- number_of_videos = len(list_of_video_paths)- assert mediapipe_2d_data.shape[0] == number_of_videos-- frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_videos_folder)-- assert (- len(set(frame_count)) == 1- ), f"Videos in {synchronized_videos_folder} have different frame counts: {frame_count}"- assert (- mediapipe_2d_data.shape[1] == frame_count[0]- ), f"Number of frames in {mediapipe_2d_data_file_path} does not match number of frames of videos in {synchronized_videos_folder}"-- # TODO - check number of tracked points vs 'expected' number of tracked points-- assert mediapipe_2d_data.shape[3] == 3 # x y z-- return Truediff --git a/freemocap/tests/test_mediapipe_3d_data_shape.py b/freemocap/tests/test_mediapipe_skeleton_data_shape.pysimilarity index 61%rename from freemocap/tests/test_mediapipe_3d_data_shape.pyrename to freemocap/tests/test_mediapipe_skeleton_data_shape.pyindex 3983af61..65b0b2e0 100644--- a/freemocap/tests/test_mediapipe_3d_data_shape.py+++ b/freemocap/tests/test_mediapipe_skeleton_data_shape.py@@ -1,17 +1,17 @@+import pytest+import numpy as npfrom pathlib import Pathfrom typing import Union-import numpy as np-from freemocap.tests.utilities.get_number_of_frames_of_videos_in_a_folder import (get_number_of_frames_of_videos_in_a_folder,)--def test_mediapipe_3d_data_shape(- synchronized_videos_folder: Union[str, Path],- mediapipe_3d_data_npy_path: Union[str, Path],- medipipe_reprojection_error_data_npy_path: Union[str, Path],[email protected]("synchronized_video_folder_path", "raw_skeleton_npy_file_path", "reprojection_error_file_name")+def test_mediapipe_skeleton_data_shape(+ synchronized_video_folder_path: Union[str, Path],+ raw_skeleton_npy_file_path: Union[str, Path],+ reprojection_error_file_name: Union[str, Path],):"""test that the `mediapipe 3d detection` process worked correctly by checking:@@ -23,31 +23,31 @@ def test_mediapipe_3d_data_shape("""assert Path(- mediapipe_3d_data_npy_path- ).is_file(), f"3d skeleton data file does not exist at {mediapipe_3d_data_npy_path}"+ raw_skeleton_npy_file_path+ ).is_file(), f"3d skeleton data file does not exist at {raw_skeleton_npy_file_path}"- skel3d_frame_marker_xyz = np.load(mediapipe_3d_data_npy_path)+ skel3d_frame_marker_xyz = np.load(raw_skeleton_npy_file_path)assert (len(skel3d_frame_marker_xyz.shape) == 3- ), f"3d skeleton data file should have 3 dimensions - {mediapipe_3d_data_npy_path}"+ ), f"3d skeleton data file should have 3 dimensions - {raw_skeleton_npy_file_path}"assert Path(- medipipe_reprojection_error_data_npy_path- ).is_file(), f"3d skeleton reprojection error data file does not exist at {medipipe_reprojection_error_data_npy_path}"+ reprojection_error_file_name+ ).is_file(), f"3d skeleton reprojection error data file does not exist at {reprojection_error_file_name}"skeleton_reprojection_error_fr_mar = np.load(- medipipe_reprojection_error_data_npy_path+ reprojection_error_file_name)assert (len(skeleton_reprojection_error_fr_mar.shape) == 2- ), f"3d skeleton reprojection error data file should have 2 dimensions {medipipe_reprojection_error_data_npy_path}"+ ), f"3d skeleton reprojection error data file should have 2 dimensions {reprojection_error_file_name}"- frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_videos_folder)+ frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path)assert (len(set(frame_count)) == 1- ), f"Videos in {synchronized_videos_folder} have different frame counts: {frame_count}"+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"number_of_frames = frame_count[0]@@ -58,6 +58,5 @@ def test_mediapipe_3d_data_shape(assert (skel3d_frame_marker_xyz.shape[2] == 3- ), f"3d skeleton data file does not have 3 dimensions for X,Y,Z at {mediapipe_3d_data_npy_path}"+ ), f"3d skeleton data file does not have 3 dimensions for X,Y,Z at {raw_skeleton_npy_file_path}"- return Truediff --git a/freemocap/tests/test_synchronized_video_frame_counts.py b/freemocap/tests/test_synchronized_video_frame_counts.pyindex 04f4668e..aa9f9a44 100644--- a/freemocap/tests/test_synchronized_video_frame_counts.py+++ b/freemocap/tests/test_synchronized_video_frame_counts.py@@ -1,3 +1,4 @@+import pytestfrom pathlib import Pathfrom typing import Union@@ -6,19 +7,18 @@ from freemocap.tests.utilities.get_number_of_frames_of_videos_in_a_folder import)from freemocap.utilities.get_video_paths import get_video_paths--def test_synchronized_video_frame_counts(video_folder_path: Union[Path, str]):[email protected]("synchronized_video_folder_path")+def test_synchronized_video_frame_counts(synchronized_video_folder_path: Union[Path, str]):"""Test if all the videos in this folder have precisely the same number of frames"""- list_of_video_paths = get_video_paths(Path(video_folder_path))+ list_of_video_paths = get_video_paths(Path(synchronized_video_folder_path))- assert len(list_of_video_paths) > 0, f"No videos found in {video_folder_path}"+ assert len(list_of_video_paths) > 0, f"No videos found in {synchronized_video_folder_path}"- frame_count = get_number_of_frames_of_videos_in_a_folder(video_folder_path)+ frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path)assert (len(set(frame_count)) == 1- ), f"Videos in {video_folder_path} have different frame counts: {frame_count}"+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"- return Truediff --git a/freemocap/tests/test_test.py b/freemocap/tests/test_test.pydeleted file mode 100644index 6dff5d28..00000000--- a/freemocap/tests/test_test.py+++ /dev/null@@ -1,9 +0,0 @@-def returnTrue():- try:- return True- except:- return False---def test_test():- assert returnTrue() == True\ No newline at end of filediff --git a/freemocap/tests/test_total_body_center_of_mass_data_shape.py b/freemocap/tests/test_total_body_center_of_mass_data_shape.pyindex acc41c34..22a96825 100644--- a/freemocap/tests/test_total_body_center_of_mass_data_shape.py+++ b/freemocap/tests/test_total_body_center_of_mass_data_shape.py@@ -1,37 +1,36 @@+import pytest+import numpy as npfrom pathlib import Pathfrom typing import Union-import numpy as np-from freemocap.tests.utilities.get_number_of_frames_of_videos_in_a_folder import (get_number_of_frames_of_videos_in_a_folder,)-[email protected]("synchronized_video_folder_path", "total_body_center_of_mass_file_path")def test_total_body_center_of_mass_data_shape(- synchronized_videos_folder: Union[str, Path],- total_body_center_of_mass_npy_file_path: Union[str, Path],+ synchronized_video_folder_path: Union[str, Path],+ total_body_center_of_mass_file_path: Union[str, Path],):assert Path(- total_body_center_of_mass_npy_file_path- ).is_file(), f"No file found at {total_body_center_of_mass_npy_file_path}"+ total_body_center_of_mass_file_path+ ).is_file(), f"No file found at {total_body_center_of_mass_file_path}"- total_body_center_of_mass_fr_xyz = np.load(total_body_center_of_mass_npy_file_path)+ total_body_center_of_mass_fr_xyz = np.load(total_body_center_of_mass_file_path)- frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_videos_folder)+ frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path)assert (len(set(frame_count)) == 1- ), f"Videos in {synchronized_videos_folder} have different frame counts: {frame_count}"+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"number_of_frames = frame_count[0]assert (total_body_center_of_mass_fr_xyz.shape[0] == number_of_frames- ), f"Number of frames in {total_body_center_of_mass_npy_file_path} does not match number of frames of videos in {synchronized_videos_folder}"+ ), f"Number of frames in {total_body_center_of_mass_file_path} does not match number of frames of videos in {synchronized_video_folder_path}"assert (total_body_center_of_mass_fr_xyz.shape[1] == 3), f"`total_body_center_of_mass_fr_xyz.shape[1]` should have 3 dimensions (X,Y,Z) "- return Truediff --git a/freemocap/tests/utilities/import_sample_data.py b/freemocap/tests/utilities/import_sample_data.pynew file mode 100644index 00000000..10d0cd36--- /dev/null+++ b/freemocap/tests/utilities/import_sample_data.py@@ -0,0 +1,94 @@+import io+import requests+import zipfile+from pathlib import Path++from freemocap.system.paths_and_files_names import (+ CENTER_OF_MASS_FOLDER_NAME,+ FIGSHARE_SAMPLE_DATA_FILE_NAME,+ FIGSHARE_ZIP_FILE_URL,+ MEDIAPIPE_2D_NPY_FILE_NAME,+ RAW_MEDIAPIPE_3D_NPY_FILE_NAME,+ MEDIAPIPE_REPROJECTION_ERROR_NPY_FILE_NAME,+ OUTPUT_DATA_FOLDER_NAME,+ RAW_DATA_FOLDER_NAME,+ SYNCHRONIZED_VIDEOS_FOLDER_NAME,+ TOTAL_BODY_CENTER_OF_MASS_NPY_FILE_NAME,+)+++def load_sample_data() -> Path:+ extract_to_path = Path.home()+ extract_to_path.mkdir(exist_ok=True)++ figshare_sample_data_path = extract_to_path / FIGSHARE_SAMPLE_DATA_FILE_NAME++ if not Path.exists(figshare_sample_data_path):+ r = requests.get(FIGSHARE_ZIP_FILE_URL)+ z = zipfile.ZipFile(io.BytesIO(r.content))+ z.extractall(extract_to_path)++ return figshare_sample_data_path+++def find_data_folder_path(session_folder_path: Path) -> Path:+ for subfolder_path in session_folder_path.iterdir():+ if subfolder_path.name == OUTPUT_DATA_FOLDER_NAME:+ return subfolder_path++ raise Exception(f"Could not find a data folder in path {str(session_folder_path)}")+++def find_synchronized_videos_folder_path(session_folder_path: Path) -> Path:+ for subfolder_path in session_folder_path.iterdir():+ if subfolder_path.name == SYNCHRONIZED_VIDEOS_FOLDER_NAME:+ return subfolder_path++ raise Exception(f"Could not find a videos folder in path {str(session_folder_path)}")+++def find_raw_skeleton_npy_file_name(data_folder_name: Path) -> Path:+ raw_data_subfolder_path = data_folder_name / RAW_DATA_FOLDER_NAME+ if raw_data_subfolder_path.exists:+ raw_data_npy_path_list = [path.name for path in raw_data_subfolder_path.glob("*.npy")]+ if RAW_MEDIAPIPE_3D_NPY_FILE_NAME in raw_data_npy_path_list:+ return raw_data_subfolder_path / RAW_MEDIAPIPE_3D_NPY_FILE_NAME++ raise Exception(f"Could not find a skeleton NPY file in path {str(data_folder_name)}")+++def find_total_body_center_of_mass_file_name(data_folder_name: Path) -> Path:+ center_of_mass_subfolder_path = data_folder_name / CENTER_OF_MASS_FOLDER_NAME+ if center_of_mass_subfolder_path.exists:+ center_of_mass_npy_path_list = [path.name for path in center_of_mass_subfolder_path.glob("*.npy")]++ if TOTAL_BODY_CENTER_OF_MASS_NPY_FILE_NAME in center_of_mass_npy_path_list:+ return center_of_mass_subfolder_path / TOTAL_BODY_CENTER_OF_MASS_NPY_FILE_NAME++ raise Exception(f"Could not find a total body center of mass npy file in path {str(data_folder_name)}")+++def find_image_tracking_data_file_name(data_folder_name: Path) -> Path:+ raw_data_subfolder_path = data_folder_name / RAW_DATA_FOLDER_NAME+ if raw_data_subfolder_path.exists:+ raw_data_npy_path_list = [path.name for path in raw_data_subfolder_path.glob("*.npy")]++ if MEDIAPIPE_2D_NPY_FILE_NAME in raw_data_npy_path_list:+ return raw_data_subfolder_path / MEDIAPIPE_2D_NPY_FILE_NAME++ raise Exception(f"Could not find a 2d data file in path {str(data_folder_name)}")+++def find_reprojection_error_file_name(data_folder_name: Path) -> Path:+ raw_data_subfolder_path = data_folder_name / RAW_DATA_FOLDER_NAME+ if raw_data_subfolder_path.exists:+ raw_data_npy_path_list = [path.name for path in raw_data_subfolder_path.glob("*.npy")]++ if MEDIAPIPE_REPROJECTION_ERROR_NPY_FILE_NAME in raw_data_npy_path_list:+ return raw_data_subfolder_path / MEDIAPIPE_REPROJECTION_ERROR_NPY_FILE_NAME++ raise Exception(f"Could not find reprojection error data file in path {str(data_folder_name)}")+++if __name__ == "__main__":+ sample_data_path = load_sample_data()diff --git a/freemocap/tests/utilities/process_recording_headless.py b/freemocap/tests/utilities/process_recording_headless.pynew file mode 100644index 00000000..046598ab--- /dev/null+++ b/freemocap/tests/utilities/process_recording_headless.py@@ -0,0 +1,48 @@+import logging+from pathlib import Path+from typing import Optional, Union+from freemocap.core_processes.process_motion_capture_videos.process_recording_folder import process_recording_folder+from freemocap.core_processes.export_data.blender_stuff.export_to_blender import export_to_blender+from freemocap.parameter_info_models.recording_info_model import RecordingInfoModel+from freemocap.parameter_info_models.recording_processing_parameter_models import RecordingProcessingParameterModel+from freemocap.system.paths_and_files_names import get_blender_file_path++logger = logging.getLogger(__name__)+++def process_recording_headless(+ recording_path: Union[str, Path],+ path_to_camera_calibration_toml: Optional[Union[str, Path]] = None,+ path_to_blender_executable: Optional[Union[str, Path]] = None,+):+ rec = RecordingProcessingParameterModel()++ rec.recording_info_model = RecordingInfoModel(recording_folder_path=Path(recording_path))++ if path_to_camera_calibration_toml:+ rec.recording_info_model.calibration_toml_path = Path(path_to_camera_calibration_toml)+ else:+ logger.warning("No camera calibration toml file provided. May cause an error with multicamera recordings.")++ process_recording_folder(recording_processing_parameter_model=rec)++ if path_to_blender_executable:+ blender_file_path = get_blender_file_path(recording_folder_path=recording_path)+ logger.info(f"Exporting to {blender_file_path}")+ export_to_blender(+ recording_folder_path=recording_path,+ blender_file_path=blender_file_path,+ blender_exe_path=Path(path_to_blender_executable),+ )+ else:+ logger.warning("No blender executable provided. Blender file will not be exported.")++def find_calibration_toml_path(recording_path: Union[str, Path]) -> Path:+ for file in recording_path.glob('*calibration.toml'):+ return Path(file)++if __name__ == "__main__":+ recording_path = Path("PATH/TO/RECORDING/FOLDER")+ blender_path = Path("PATH/TO/BLENDER/EXECUTABLE")++ process_recording_headless(recording_path=recording_path, path_to_blender_executable=blender_path)