Skip to content

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

TypeScript

Updating status checker (#574)

philipqueenaae165797f69
diff --git a/freemocap/data_layer/recording_models/recording_info_model.py b/freemocap/data_layer/recording_models/recording_info_model.py
index 817865eb..aa6c3c8c 100644
--- a/freemocap/data_layer/recording_models/recording_info_model.py
+++ b/freemocap/data_layer/recording_models/recording_info_model.py
@@ -21,6 +21,7 @@ from freemocap.tests.test_image_tracking_data_shape import test_image_tracking_d
from freemocap.tests.test_mediapipe_skeleton_data_shape import test_mediapipe_skeleton_data_shape
from freemocap.tests.test_synchronized_video_frame_counts import test_synchronized_video_frame_counts
from freemocap.tests.test_total_body_center_of_mass_data_shape import test_total_body_center_of_mass_data_shape
+from freemocap.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
logger = logging.getLogger(__name__)
@@ -153,7 +154,7 @@ class RecordingFolderStatusChecker:
self.recording_info_model = recording_info_model
@property
- def status_check(self) -> Dict[str, Union[bool, str, float]]:
+ def status_check(self) -> Dict[str, Union[bool, str, float, dict]]:
return {
"synchronized_videos_status_check": self.check_synchronized_videos_status(),
"data2d_status_check": self.check_data2d_status(),
@@ -227,35 +228,37 @@ class RecordingFolderStatusChecker:
toml_status = self.check_for_calibration_toml_with_different_name()
return toml_status
- def get_number_of_mp4s_in_synched_videos_directory(self) -> float:
+ def get_number_of_mp4s_in_synched_videos_directory(self) -> int:
synchronized_directory_path = Path(self.recording_info_model.synchronized_videos_folder_path)
- video_count = 0.0
if not synchronized_directory_path.exists():
- return video_count
+ return 0
- for file in synchronized_directory_path.iterdir():
- if file.is_file() and file.suffix.lower() == ".mp4":
- video_count += 1
+ video_count = len(get_video_paths(synchronized_directory_path))
- logger.info(f"Number of `.mp4`'s in {self.recording_info_model.synchronized_videos_folder_path}: {video_count}")
+ logger.info(f"Number of `.mp4`'s in {synchronized_directory_path}: {video_count}")
return video_count
- def get_number_of_frames_in_videos(self):
+ def get_number_of_frames_in_videos(self) -> Dict[str, int]:
timestamps_directory_path = Path(self.recording_info_model.synchronized_videos_folder_path) / "timestamps"
- if not timestamps_directory_path.exists():
- return "No 'timestamps' directory found" # TODO: Check frame status without using timestamps with openCV or FFProbe
-
if timestamps_directory_path.exists():
frame_counts = {}
for npy_file in timestamps_directory_path.iterdir():
if npy_file.is_file() and npy_file.suffix.lower() == ".npy":
video_npy = np.load(str(npy_file))
- frame_counts[npy_file.name] = str(len(video_npy) - 1)
-
- return frame_counts
+ frame_counts[npy_file.name] = len(video_npy) - 1
+ else:
+ logger.debug("No 'timestamps' directory, finding frame counts from synchronized videos")
+ try:
+ frame_counts = get_number_of_frames_of_videos_in_a_folder(
+ self.recording_info_model.synchronized_videos_folder_path
+ )
+ except ValueError:
+ frame_counts = {}
+
+ return frame_counts
def check_for_calibration_toml_with_different_name(self) -> bool:
try:
diff --git a/freemocap/tests/test_image_tracking_data_shape.py b/freemocap/tests/test_image_tracking_data_shape.py
index 9fa64484..3f49b2a6 100644
--- a/freemocap/tests/test_image_tracking_data_shape.py
+++ b/freemocap/tests/test_image_tracking_data_shape.py
@@ -34,13 +34,13 @@ def test_image_tracking_data_shape(
image_tracking_data.shape[0] == number_of_videos
), f"Number of videos in {image_tracking_data_file_path} 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)
+ frame_counts = list(get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path).values())
assert (
- len(set(frame_count)) == 1
- ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"
+ len(set(frame_counts)) == 1
+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_counts}"
assert (
- image_tracking_data.shape[1] == frame_count[0]
+ image_tracking_data.shape[1] == frame_counts[0]
), f"Number of frames in {image_tracking_data_file_path} 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
diff --git a/freemocap/tests/test_mediapipe_skeleton_data_shape.py b/freemocap/tests/test_mediapipe_skeleton_data_shape.py
index 5a529fda..e26e79a3 100644
--- a/freemocap/tests/test_mediapipe_skeleton_data_shape.py
+++ b/freemocap/tests/test_mediapipe_skeleton_data_shape.py
@@ -44,12 +44,12 @@ def test_mediapipe_skeleton_data_shape(
len(skeleton_reprojection_error_fr_mar.shape) == 2
), f"3d skeleton reprojection error data file should have 2 dimensions {reprojection_error_file_path}"
- frame_count = get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path)
+ frame_counts = list(get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path).values())
assert (
- len(set(frame_count)) == 1
- ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"
+ len(set(frame_counts)) == 1
+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_counts}"
- number_of_frames = frame_count[0]
+ number_of_frames = frame_counts[0]
assert skel3d_frame_marker_xyz.shape[0] == number_of_frames
assert skeleton_reprojection_error_fr_mar.shape[0] == number_of_frames
diff --git a/freemocap/tests/test_synchronized_video_frame_counts.py b/freemocap/tests/test_synchronized_video_frame_counts.py
index fd219dc0..e4bb44a1 100644
--- a/freemocap/tests/test_synchronized_video_frame_counts.py
+++ b/freemocap/tests/test_synchronized_video_frame_counts.py
@@ -18,8 +18,8 @@ def test_synchronized_video_frame_counts(synchronized_video_folder_path: Union[P
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(synchronized_video_folder_path)
+ frame_counts = list(get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path).values())
assert (
- len(set(frame_count)) == 1
- ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"
+ len(set(frame_counts)) == 1
+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_counts}"
diff --git a/freemocap/tests/test_total_body_center_of_mass_data_shape.py b/freemocap/tests/test_total_body_center_of_mass_data_shape.py
index 87eaa1fe..285d0530 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
@@ -20,12 +20,12 @@ def test_total_body_center_of_mass_data_shape(
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_video_folder_path)
+ frame_counts = list(get_number_of_frames_of_videos_in_a_folder(synchronized_video_folder_path).values())
assert (
- len(set(frame_count)) == 1
- ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_count}"
+ len(set(frame_counts)) == 1
+ ), f"Videos in {synchronized_video_folder_path} have different frame counts: {frame_counts}"
- number_of_frames = frame_count[0]
+ number_of_frames = frame_counts[0]
assert (
total_body_center_of_mass_fr_xyz.shape[0] == number_of_frames
diff --git a/freemocap/utilities/get_number_of_frames_of_videos_in_a_folder.py b/freemocap/utilities/get_number_of_frames_of_videos_in_a_folder.py
index 30fe3a31..3b02fcdf 100644
--- a/freemocap/utilities/get_number_of_frames_of_videos_in_a_folder.py
+++ b/freemocap/utilities/get_number_of_frames_of_videos_in_a_folder.py
@@ -9,7 +9,7 @@ from freemocap.utilities.get_video_paths import get_video_paths
logger = logging.getLogger(__name__)
-def get_number_of_frames_of_videos_in_a_folder(folder_path: Union[str, Path]):
+def get_number_of_frames_of_videos_in_a_folder(folder_path: Union[str, Path]) -> dict[str, int]:
"""
Get the number of frames in the first video in a folder
"""
@@ -18,12 +18,12 @@ def get_number_of_frames_of_videos_in_a_folder(folder_path: Union[str, Path]):
if len(list_of_video_paths) == 0:
logger.error(f"No videos found in {folder_path}")
- return None
+ raise ValueError(f"No videos found in {folder_path}")
- frame_count = []
+ frame_count = {}
for video_path in list_of_video_paths:
cap = cv2.VideoCapture(str(video_path))
- frame_count.append(int(cap.get(cv2.CAP_PROP_FRAME_COUNT)))
+ frame_count[video_path.name] = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
cap.release()
return frame_count