Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Pose2Sim/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,12 @@ def calibrate_intrinsics(calib_dir, intrinsics_config_dict, save_debug_images=Tr
if show_detection_intrinsics == True:
# If previously labeled points exist, check if they are satisfying
if 'image_points' in locals():
imgp = next((entry['image_points_2d'] for entry in image_points if entry["cam_name"] == cam_name), [])
objp = next((entry['object_points_3d'] for entry in image_points if entry["cam_name"] == cam_name), [])
if len(imgp) > 0 and len(objp) > 0:
cached_imgp = next((entry['image_points_2d'] for entry in image_points if entry["cam_name"] == cam_name), [])
cached_objp = next((entry['object_points_3d'] for entry in image_points if entry["cam_name"] == cam_name), [])
if len(cached_imgp) > 0 and len(cached_objp) > 0:
# recalculate reprojected points
imgp = np.array(imgp).reshape(-1, 2)
objp = np.array(objp).reshape(-1, 3)
imgp = np.array(cached_imgp).reshape(-1, 2)
objp = np.array(cached_objp).reshape(-1, 3)
saved_img_path = create_image_labels(img_path, imgp, calib_dir, 'int', reprojected_points=None, show=True, save=save_debug_images)
# Are you satisfied? If so, add to imgpoints and continue; else, redo detection
satisfied = show_qt_message_box(
Expand Down Expand Up @@ -1440,7 +1440,7 @@ def extract_frames(video_path, extract_every_N_sec=1, overwrite_extraction=False
- extracted frames in folder
'''

if not Path(Path(video_path).exists().stem + '_00000.png') or overwrite_extraction:
if not list(Path(video_path).parent.glob(f'{Path(video_path).stem}_*.png')) or overwrite_extraction:
cap = cv2.VideoCapture(str(video_path))
if cap.isOpened():
fps = round(cap.get(cv2.CAP_PROP_FPS))
Expand All @@ -1450,7 +1450,7 @@ def extract_frames(video_path, extract_every_N_sec=1, overwrite_extraction=False
ret, frame = cap.read()
if ret == True:
if frame_nb % (fps*extract_every_N_sec) == 0:
img_path = (Path(video_path).stem + '_' +str(frame_nb).zfill(5)+'.png')
img_path = Path(video_path).parent / (Path(video_path).stem + '_' +str(frame_nb).zfill(5)+'.png')
cv2.imwrite(str(img_path), frame)
frame_nb+=1
else:
Expand Down
35 changes: 27 additions & 8 deletions Pose2Sim/markerAugmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def augment_markers_all(config_dict):
frame_range = config_dict.get('project', {}).get('frame_range', 'auto')
subject_height = config_dict.get('project', {}).get('participant_height', 'auto')
subject_mass = config_dict.get('project', {}).get('participant_mass', 70.0)

multi_person = config_dict.get('project', {}).get('multi_person', False)

large_hip_knee_angles = config_dict.get('kinematics', {}).get('large_hip_knee_angles', 90)
trimmed_extrema_percent = config_dict.get('kinematics', {}).get('trimmed_extrema_percent', 50)
default_height = config_dict.get('kinematics', {}).get('default_height', 1.7)
Expand All @@ -112,6 +113,12 @@ def augment_markers_all(config_dict):
trc_files = trc_no_filtering
sorted(trc_files, key=natural_sort_key)

if not multi_person and len(trc_files) > 1:
most_recent_trc_file = max(trc_files, key=lambda f: f.stat().st_mtime)
ignored_trc_files = [f.name for f in trc_files if f != most_recent_trc_file]
logging.warning(f"multi_person is set to false in Config.toml but {len(trc_files)} trc files were found in {pose_3d_dir}. Using the most recently modified one ({most_recent_trc_file.name}) and ignoring {ignored_trc_files}.")
trc_files = [most_recent_trc_file]

# Add missing markers if needed
for trc_file in trc_files:
# Import TRC file
Expand Down Expand Up @@ -160,22 +167,34 @@ def augment_markers_all(config_dict):
subject_height.append(height)
elif not type(subject_height) == list: # int or float
subject_height = [subject_height]
if len(subject_height) < len(trc_files):
logging.warning(f"Number of subject heights does not match number of TRC files. Missing heights are set to {default_height}m.")
subject_height += [default_height] * (len(trc_files) - len(subject_height))
if len(subject_height) != len(trc_files):
if not multi_person:
raise ValueError(f"Multi_person is set to false in Config.toml but participant_height has {len(subject_height)} value(s) while {len(trc_files)} trc file(s) were found. Expected exactly one matching value.")
elif len(subject_height) < len(trc_files):
logging.warning(f"Number of subject heights does not match number of TRC files. Missing heights are set to {default_height}m.")
subject_height += [default_height] * (len(trc_files) - len(subject_height))
else:
logging.warning("Number of subject heights does not match number of TRC files. Extra heights are ignored.")
subject_height = subject_height[:len(trc_files)]

# Get subject masses
if subject_mass is None or subject_mass == 0:
subject_mass = [70] * len(trc_files)
logging.warning("No subject mass found in Config.toml. Using default mass of 70kg.")
elif not type(subject_mass) == list:
subject_mass = [subject_mass]
if len(subject_mass) < len(trc_files):
logging.warning("Number of subject masses does not match number of TRC files. Missing masses are set to 70kg.")
subject_mass += [70] * (len(trc_files) - len(subject_mass))
if len(subject_mass) != len(trc_files):
if not multi_person:
raise ValueError(f"Multi_person is set to false in Config.toml but participant_mass has {len(subject_mass)} value(s) while {len(trc_files)} trc file(s) were found. Expected exactly one matching value.")
elif len(subject_mass) < len(trc_files):
logging.warning("Number of subject masses does not match number of TRC files. Missing masses are set to 70kg.")
subject_mass += [70] * (len(trc_files) - len(subject_mass))
else:
logging.warning("Number of subject masses does not match number of TRC files. Extra masses are ignored.")
subject_mass = subject_mass[:len(trc_files)]

# Run marker augmentation
for p in range(len(subject_mass)):
for p in range(len(trc_files)):
trc_file = trc_files[p]
trc_file_out = Path(trc_file).stem + f'_{augmenterModelName}.trc'

Expand Down
2 changes: 1 addition & 1 deletion Pose2Sim/synchronization.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ def synchronize_cams_all(config_dict):
nb_frames_per_cam = [len(fnmatch.filter(os.listdir(json_dir), '*.json')) for json_dir in json_dirs]
cam_nb = len(json_dirs)
cam_list = list(range(cam_nb))
cam_names = [Path(j_dir).name.split('_')[0] for j_dir in json_dirs]
cam_names = [re.sub(r'_json$', '', Path(j_dir).name) for j_dir in json_dirs]

# frame range selection
f_range = [[0, min([len(j) for j in json_files_names])] if frame_range in ('all', 'auto', []) else frame_range][0]
Expand Down