Skip to content

Commit fa3ed0a

Browse files
committed
export IK to bvh for MoCap
1 parent 3ccc8f7 commit fa3ed0a

7 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎Pose2Sim/Demo_Batch/Config.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ use_simple_model = false # true or false # >10 times faster IK if true. No muscl
302302
filter_ik = false # true or false # Useful for force estimations if results are noisy
303303
ik_filter_type = 'acc_minimizing' # butterworth, acc_minimizing, kalman, one_euro, gcv_spline, gaussian, LOESS, median, butterworth_on_speed
304304
# see and edit the filtering parameters in the [filtering] section
305+
make_bvh = true # save kinematics in bvh format in addition to osim and mot (for motion capture software)
305306

306307
right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
307308
default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model

‎Pose2Sim/Demo_Batch/Trial_1/Config.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
# filter_ik = false # true or false # Useful for force estimations if results are noisy
303303
# ik_filter_type = 'acc_minimizing' # butterworth, acc_minimizing, kalman, one_euro, gcv_spline, gaussian, LOESS, median, butterworth_on_speed
304304
# # see and edit the filtering parameters in the [filtering] section
305+
# make_bvh = true # save kinematics in bvh format in addition to osim and mot (for motion capture software)
305306

306307
# right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
307308
# default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model

‎Pose2Sim/Demo_Batch/Trial_2/Config.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ keypoints_to_consider = ['RWrist'] # 'all' if all points should be considered, f
300300
# filter_ik = false # true or false # Useful for force estimations if results are noisy
301301
# ik_filter_type = 'acc_minimizing' # butterworth, acc_minimizing, kalman, one_euro, gcv_spline, gaussian, LOESS, median, butterworth_on_speed
302302
# # see and edit the filtering parameters in the [filtering] section
303+
# make_bvh = true # save kinematics in bvh format in addition to osim and mot (for motion capture software)
303304

304305
# right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
305306
# default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model

‎Pose2Sim/Demo_MultiPerson/Config.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ use_simple_model = false # true or false # >10 times faster IK if true. No muscl
301301
filter_ik = false # true or false # Useful for force estimations if results are noisy
302302
ik_filter_type = 'acc_minimizing' # butterworth, acc_minimizing, kalman, one_euro, gcv_spline, gaussian, LOESS, median, butterworth_on_speed
303303
# see and edit the filtering parameters in the [filtering] section
304+
make_bvh = true # save kinematics in bvh format in addition to osim and mot (for motion capture software)
304305

305306
right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
306307
default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model

‎Pose2Sim/Demo_SinglePerson/Config.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ use_simple_model = false # true or false # >10 times faster IK if true. No muscl
299299
filter_ik = false # true or false # Useful for force estimations if results are noisy
300300
ik_filter_type = 'acc_minimizing' # butterworth, acc_minimizing, kalman, one_euro, gcv_spline, gaussian, LOESS, median, butterworth_on_speed
301301
# see and edit the filtering parameters in the [filtering] section
302+
make_bvh = true # save kinematics in bvh format in addition to osim and mot (for motion capture software)
302303

303304
right_left_symmetry = true # true or false (lowercase) # Set to false only if you have good reasons to think the participant is not symmetrical (e.g. prosthetic limb)
304305
default_height = 1.7 # meters # If automatic height calculation did not work, this value is used to scale the model

‎Pose2Sim/Utilities/tests.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def test_workflow(self, mock_input):
155155
config_dict.get("pose").update({"save_video":'none'})
156156
config_dict.get('synchronization').update({'keypoints_to_consider':['RWrist']})
157157
config_dict.get('kinematics').update({'use_simple_model':True})
158+
config_dict.get('kinematics').update({'make_bvh':False})
158159
Pose2Sim.runAll(config_dict)
159160

160161

@@ -183,6 +184,7 @@ def test_workflow(self, mock_input):
183184
config_dict.get("filtering").update({"display_figures":False})
184185
config_dict.get("filtering").update({"save_filt_plots":False})
185186
config_dict.get('kinematics').update({'use_simple_model':True})
187+
config_dict.get('kinematics').update({'make_bvh':False})
186188

187189
# 1. Run step by step
188190
Pose2Sim.calibration(config_dict)

‎Pose2Sim/kinematics.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
trimmed_mean, compute_height, get_max_workers
4949
from Pose2Sim.filtering import filter_all
5050
from Pose2Sim.skeletons import *
51+
from Pose2Sim.Utilities.osim_to_bvh import export_to_bvh
5152

5253
import locale
5354
locale.setlocale(locale.LC_NUMERIC, 'C')
@@ -614,6 +615,7 @@ def kinematics_all(config_dict):
614615
use_augmentation = config_dict.get('kinematics', {}).get('use_augmentation', True)
615616
use_simple_model = config_dict.get('kinematics', {}).get('use_simple_model', False)
616617
filter_ik = config_dict.get('kinematics', {}).get('filter_ik', False)
618+
make_bvh = config_dict.get('kinematics', {}).get('make_bvh', True)
617619
multi_person = config_dict.get('project', {}).get('multi_person', False)
618620
parallel_workers = config_dict.get('kinematics', {}).get('parallel_workers_kinematics', 'auto')
619621
right_left_symmetry = config_dict.get('kinematics', {}).get('right_left_symmetry', True)
@@ -754,3 +756,13 @@ def kinematics_all(config_dict):
754756
config_dict['filtering']['type'] = config_dict.get('kinematics', {}).get('ik_filter_type', 'acc_minimizing')
755757

756758
filter_all(config_dict)
759+
760+
if make_bvh:
761+
logging.info(f"\nExporting OpenSim results to BVH files...")
762+
for trc_file in trc_files:
763+
osim_path = (kinematics_dir / (trc_file.stem + '.osim')).resolve()
764+
mot_path = Path(kinematics_dir, trc_file.stem + '.mot').resolve()
765+
bvh_path = Path(kinematics_dir, trc_file.stem + '_ik.bvh').resolve()
766+
export_to_bvh(
767+
model_path=osim_path, output_path=bvh_path, motion_path=mot_path)
768+

0 commit comments

Comments
 (0)