minor script changes
This commit is contained in:
parent
ecd39ff943
commit
1c2fc6d9d1
@ -19,8 +19,8 @@
|
|||||||
Usage:
|
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>')
|
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
|
||||||
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 -o -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 -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=[
|
# MODEL = Node("None", id=None, children=[
|
||||||
# Node("Origin", id=0),
|
# Node("Origin", id=0),
|
||||||
# Node("Board1", id=1),
|
# Node("Board1", id=1),
|
||||||
@ -349,24 +349,26 @@ def reproj_from_trc_calib_func(**args):
|
|||||||
'hand_right_keypoints_3d':[]}]
|
'hand_right_keypoints_3d':[]}]
|
||||||
# write one json file per camera and per frame
|
# write one json file per camera and per frame
|
||||||
for cam, cam_dir in enumerate(cam_dirs):
|
for cam, cam_dir in enumerate(cam_dirs):
|
||||||
print('\n', cam)
|
|
||||||
for frame in range(len(Q)):
|
for frame in range(len(Q)):
|
||||||
json_dict_copy = deepcopy(json_dict)
|
json_dict_copy = deepcopy(json_dict)
|
||||||
data_proj_frame = data_proj[cam].iloc[row]['DavidPagnon']['person0']
|
data_proj_frame = data_proj[cam].iloc[row]['DavidPagnon']['person0']
|
||||||
# store 2D keypoints and respect model keypoint order
|
# store 2D keypoints and respect model keypoint order
|
||||||
for (i,b) in zip(bodyparts_ids, bodyparts):
|
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'][[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()
|
json_dict_copy['people'][0]['pose_keypoints_2d'] = json_dict_copy['people'][0]['pose_keypoints_2d'].tolist()
|
||||||
# write json file
|
# write json file
|
||||||
json_file = os.path.join(cam_dir, f'{filename}_cam_{cam+1:02d}.{frame:05d}.json')
|
json_file = os.path.join(cam_dir, f'{filename}_cam_{cam+1:02d}.{frame:05d}.json')
|
||||||
with open(json_file, 'w') as js_f:
|
with open(json_file, 'w') as js_f:
|
||||||
js_f.write(json.dumps(json_dict_copy))
|
js_f.write(json.dumps(json_dict_copy))
|
||||||
|
print('Camera #', cam, 'done.')
|
||||||
|
|
||||||
# Wrong format
|
# Wrong format
|
||||||
else:
|
else:
|
||||||
raise ValueError('output_format must be either "openpose" or "deeplabcut"')
|
raise ValueError('output_format must be either "openpose" or "deeplabcut"')
|
||||||
|
|
||||||
|
print(f'Reprojected points saved at {output_file_root}.')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
Beware, it can be quite slow depending on the ccomplexity
|
Beware, it can be quite slow depending on the ccomplexity
|
||||||
of the model and on the number of frames.
|
of the model and on the number of frames.
|
||||||
|
|
||||||
|
Also, make sure that OpenSim is installed (e.g. via conda)
|
||||||
|
|
||||||
Usage:
|
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>')
|
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
|
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 = []
|
marker_positions = []
|
||||||
print('Time frame:')
|
print('Time frame:')
|
||||||
for n,t in enumerate(times):
|
for n,t in enumerate(times):
|
||||||
print(t, 's')
|
print('t = ', t, 's')
|
||||||
# put the model in the right position
|
# put the model in the right position
|
||||||
for coord in joint_angle_set_names:
|
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'):
|
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:
|
with open(trc_path, 'w') as trc_o:
|
||||||
trc_o.write(header_trc+'\n')
|
trc_o.write(header_trc+'\n')
|
||||||
marker_positions_pd.to_csv(trc_path, header=False, sep = '\t', mode='a', index=False)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user