minor script changes

This commit is contained in:
davidpagnon 2024-02-20 17:21:47 +01:00
parent ecd39ff943
commit 1c2fc6d9d1
2 changed files with 12 additions and 7 deletions

View File

@ -19,8 +19,8 @@
Usage:
from Pose2Sim.Utilities import reproj_from_trc_calib; reproj_from_trc_calib.reproj_from_trc_calib_func(r'<input_trc_file>', r'<input_calib_file>', '<output_format>', r'<output_file_root>')
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()

View File

@ -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'<input_mot_file>', r'<output_osim_file>', r'<output_trc_file>')
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__':