From 1c2fc6d9d16f1b50abc18be17aaa11adea56b596 Mon Sep 17 00:00:00 2001 From: davidpagnon Date: Tue, 20 Feb 2024 17:21:47 +0100 Subject: [PATCH] minor script changes --- Pose2Sim/Utilities/reproj_from_trc_calib.py | 14 ++++++++------ Pose2Sim/Utilities/trc_from_mot_osim.py | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Pose2Sim/Utilities/reproj_from_trc_calib.py b/Pose2Sim/Utilities/reproj_from_trc_calib.py index 7d74d1b..dbc8f0c 100644 --- a/Pose2Sim/Utilities/reproj_from_trc_calib.py +++ b/Pose2Sim/Utilities/reproj_from_trc_calib.py @@ -19,8 +19,8 @@ Usage: from Pose2Sim.Utilities import reproj_from_trc_calib; reproj_from_trc_calib.reproj_from_trc_calib_func(r'', r'', '', r'') python -m reproj_from_trc_calib -t input_trc_file -c input_calib_file - python -m reproj_from_trc_calib -t input_trc_file -c input_calib_file -f 'openpose' -u - python -m reproj_from_trc_calib -t input_trc_file -c input_calib_file -f 'deeplabcut' -o output_file_root + python -m reproj_from_trc_calib -t input_trc_file -c input_calib_file -o -u + python -m reproj_from_trc_calib -t input_trc_file -c input_calib_file -d -o output_file_root ''' @@ -90,7 +90,7 @@ MODEL = Node("CHip", id=None, children=[ ]), ]) -nb_joints = 17 +# nb_joints = 17 # MODEL = Node("None", id=None, children=[ # Node("Origin", id=0), # Node("Board1", id=1), @@ -349,24 +349,26 @@ def reproj_from_trc_calib_func(**args): 'hand_right_keypoints_3d':[]}] # write one json file per camera and per frame for cam, cam_dir in enumerate(cam_dirs): - print('\n', cam) for frame in range(len(Q)): json_dict_copy = deepcopy(json_dict) data_proj_frame = data_proj[cam].iloc[row]['DavidPagnon']['person0'] # store 2D keypoints and respect model keypoint order for (i,b) in zip(bodyparts_ids, bodyparts): - print(repr(data_proj_frame[b].values)) + # print(repr(data_proj_frame[b].values)) json_dict_copy['people'][0]['pose_keypoints_2d'][[i*3,i*3+1,i*3+2]] = np.append(data_proj_frame[b].values, 1) json_dict_copy['people'][0]['pose_keypoints_2d'] = json_dict_copy['people'][0]['pose_keypoints_2d'].tolist() # write json file json_file = os.path.join(cam_dir, f'{filename}_cam_{cam+1:02d}.{frame:05d}.json') with open(json_file, 'w') as js_f: js_f.write(json.dumps(json_dict_copy)) - + print('Camera #', cam, 'done.') + # Wrong format else: raise ValueError('output_format must be either "openpose" or "deeplabcut"') + print(f'Reprojected points saved at {output_file_root}.') + if __name__ == '__main__': parser = argparse.ArgumentParser() diff --git a/Pose2Sim/Utilities/trc_from_mot_osim.py b/Pose2Sim/Utilities/trc_from_mot_osim.py index 3c4258d..b5c2d15 100644 --- a/Pose2Sim/Utilities/trc_from_mot_osim.py +++ b/Pose2Sim/Utilities/trc_from_mot_osim.py @@ -13,6 +13,8 @@ Beware, it can be quite slow depending on the ccomplexity of the model and on the number of frames. + Also, make sure that OpenSim is installed (e.g. via conda) + Usage: from Pose2Sim.Utilities import trc_from_mot_osim; trc_from_mot_osim.trc_from_mot_osim_func(r'', r'', r'') python -m trc_from_mot_osim -m input_mot_file -o input_osim_file @@ -68,7 +70,7 @@ def get_marker_positions(motion_data, model, in_degrees=True): marker_positions = [] print('Time frame:') for n,t in enumerate(times): - print(t, 's') + print('t = ', t, 's') # put the model in the right position for coord in joint_angle_set_names: if in_degrees and not coord.endswith('_tx') and not coord.endswith('_ty') and not coord.endswith('_tz'): @@ -159,6 +161,7 @@ def trc_from_mot_osim_func(*args): with open(trc_path, 'w') as trc_o: trc_o.write(header_trc+'\n') marker_positions_pd.to_csv(trc_path, header=False, sep = '\t', mode='a', index=False) + print(f'trc file successfully saved as {trc_path}') if __name__ == '__main__':