Skip to content

Commit

Permalink
beta test opensim scaling and kinematics with edits
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpagnon committed Sep 20, 2024
1 parent e321228 commit 65e675a
Show file tree
Hide file tree
Showing 13 changed files with 557 additions and 474 deletions.
15 changes: 5 additions & 10 deletions Pose2Sim/Demo_Batch/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ calibration_type = 'convert' # 'convert' or 'calculate'


[triangulation]
reorder_trc = false # only checked if multi_person analysis
reproj_error_threshold_triangulation = 15 # px
likelihood_threshold_triangulation= 0.3
min_cameras_for_triangulation = 2
Expand Down Expand Up @@ -181,14 +180,10 @@ make_c3d = true # save triangulated data in c3d format in addition to trc


[opensim]
static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']
opensim_bin_path = 'C:\OpenSim 4.4\bin'
use_augmentation = false # If using augmented measurements then set it true
load_trc_name = 'filtered' # 'default' or 'filtered', if use_augmentation = true, this line will be ignored instead using __LSTM.trc
IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]
use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
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)
remove_individual_scaling_setup = true # true or false (lowercase) # If true, the individual scaling setup files are removed to avoid cluttering
remove_individual_IK_setup = true # true or false (lowercase) # If true, the individual IK setup files are removed to avoid cluttering



Expand All @@ -204,7 +199,7 @@ IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]
# Check your model hierarchy with: for pre, _, node in RenderTree(model):
# print(f'{pre}{node.name} id={node.id}')
[pose.CUSTOM]
name = "CHip"
name = "Hip"
id = "19"
[[pose.CUSTOM.children]]
name = "RHip"
Expand Down
15 changes: 5 additions & 10 deletions Pose2Sim/Demo_Batch/Trial_1/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@


# [triangulation]
# reorder_trc = false # only checked if multi_person analysis
# reproj_error_threshold_triangulation = 15 # px
# likelihood_threshold_triangulation= 0.3
# min_cameras_for_triangulation = 2
Expand Down Expand Up @@ -181,14 +180,10 @@


# [opensim]
#static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']
#opensim_bin_path = 'C:\OpenSim 4.4\bin'
#use_augmentation = false # If using augmented measurements then set it true
#load_trc_name = 'filtered' # 'default' or 'filtered', if use_augmentation = true, this line will be ignored instead using __LSTM.trc
#IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]
# use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
# 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)
# remove_individual_scaling_setup = true # true or false (lowercase) # If true, the individual scaling setup files are removed to avoid cluttering
# remove_individual_IK_setup = true # true or false (lowercase) # If true, the individual IK setup files are removed to avoid cluttering



Expand All @@ -204,7 +199,7 @@
# # Check your model hierarchy with: for pre, _, node in RenderTree(model):
# # print(f'{pre}{node.name} id={node.id}')
# [pose.CUSTOM]
# name = "CHip"
# name = "Hip"
# id = "19"
# [[pose.CUSTOM.children]]
# name = "RHip"
Expand Down
19 changes: 7 additions & 12 deletions Pose2Sim/Demo_Batch/Trial_2/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

[project]
multi_person = true # true for trials with multiple participants. If false, only the main person in scene is analyzed (and it run much faster).
participant_height = [1.72, 1.40, 1.86] # m # float if single person, list of float if multi-person (same order as the Static trials) # Only used for marker augmentation
participant_mass = [70.0, 63.5, 88.0] # kg # Only used for marker augmentation and scaling
participant_height = [1.72, 1.40] # m # float if single person, list of float if multi-person (same order as the Static trials) # Only used for marker augmentation
participant_mass = [70.0, 63.5] # kg # Only used for marker augmentation and scaling

# frame_rate = 'auto' # fps # int or 'auto'. If 'auto', finds from video (or defaults to 60 fps if you work with images)
# frame_range = [] # For example [10,300], or [] for all frames.
Expand Down Expand Up @@ -136,7 +136,6 @@ keypoints_to_consider = 'all' # 'all' if all points should be considered, for ex


# [triangulation]
# reorder_trc = false # only checked if multi_person analysis
# reproj_error_threshold_triangulation = 15 # px
# likelihood_threshold_triangulation= 0.3
# min_cameras_for_triangulation = 2
Expand Down Expand Up @@ -181,14 +180,10 @@ keypoints_to_consider = 'all' # 'all' if all points should be considered, for ex


# [opensim]
#static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']
#opensim_bin_path = 'C:\OpenSim 4.4\bin'
#use_augmentation = false # If using augmented measurements then set it true
#load_trc_name = 'filtered' # 'default' or 'filtered', if use_augmentation = true, this line will be ignored instead using __LSTM.trc
#IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]
# use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
# 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)
# remove_individual_scaling_setup = true # true or false (lowercase) # If true, the individual scaling setup files are removed to avoid cluttering
# remove_individual_IK_setup = true # true or false (lowercase) # If true, the individual IK setup files are removed to avoid cluttering



Expand All @@ -204,7 +199,7 @@ keypoints_to_consider = 'all' # 'all' if all points should be considered, for ex
# # Check your model hierarchy with: for pre, _, node in RenderTree(model):
# # print(f'{pre}{node.name} id={node.id}')
# [pose.CUSTOM]
# name = "CHip"
# name = "Hip"
# id = "19"
# [[pose.CUSTOM.children]]
# name = "RHip"
Expand Down
19 changes: 7 additions & 12 deletions Pose2Sim/Demo_MultiPerson/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

[project]
multi_person = true # true for trials with multiple participants. If false, only the main person in scene is analyzed (and it run much faster).
participant_height = [1.72, 1.40, 1.90] # m # float if single person, list of float if multi-person (same order as the Static trials) # Only used for marker augmentation
participant_mass = [70.0, 63.5, 90.0] # kg # Only used for marker augmentation and scaling
participant_height = [1.72, 1.40] # m # float if single person, list of float if multi-person (same order as the Static trials) # Only used for marker augmentation
participant_mass = [70.0, 63.5] # kg # Only used for marker augmentation and scaling

frame_rate = 'auto' # fps # int or 'auto'. If 'auto', finds from video (or defaults to 60 fps if you work with images)
frame_range = [] # For example [10,300], or [] for all frames.
Expand Down Expand Up @@ -136,7 +136,6 @@ calibration_type = 'convert' # 'convert' or 'calculate'


[triangulation]
reorder_trc = false # only checked if multi_person analysis
reproj_error_threshold_triangulation = 15 # px
likelihood_threshold_triangulation= 0.3
min_cameras_for_triangulation = 2
Expand Down Expand Up @@ -181,14 +180,10 @@ make_c3d = true # save triangulated data in c3d format in addition to trc


[opensim]
static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']
opensim_bin_path = 'C:\OpenSim 4.4\bin'
use_augmentation = false # If using augmented measurements then set it true
load_trc_name = 'filtered' # 'default' or 'filtered', if use_augmentation = true, this line will be ignored instead using __LSTM.trc
IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]
use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
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)
remove_individual_scaling_setup = true # true or false (lowercase) # If true, the individual scaling setup files are removed to avoid cluttering
remove_individual_IK_setup = true # true or false (lowercase) # If true, the individual IK setup files are removed to avoid cluttering



Expand All @@ -204,7 +199,7 @@ IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]
# Check your model hierarchy with: for pre, _, node in RenderTree(model):
# print(f'{pre}{node.name} id={node.id}')
[pose.CUSTOM]
name = "CHip"
name = "Hip"
id = "19"
[[pose.CUSTOM.children]]
name = "RHip"
Expand Down
23 changes: 8 additions & 15 deletions Pose2Sim/Demo_SinglePerson/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ output_format = 'openpose' # 'openpose', 'mmpose', 'deeplabcut', 'none' or a lis
[synchronization]
display_sync_plots = true # true or false (lowercase)
keypoints_to_consider = ['RWrist'] # 'all' if all points should be considered, for example if the participant did not perform any particicular sharp movement. In this case, the capture needs to be 5-10 seconds long at least
# ['RWrist', 'RElbow'] list of keypoint names if you want to specify the keypoints to consider.
# ['RWrist', 'RElbow'] list of keypoint names if you want to specify keypoints with a sharp vertical motion.
approx_time_maxspeed = 'auto' # 'auto' if you want to consider the whole capture (default, slower if long sequences)
# [10.0, 2.0, 8.0, 11.0] list of times in seconds, one value per camera if you want to specify the approximate time of a clear vertical event by one person standing alone in the scene
# [10.0, 2.0, 8.0, 11.0] list of times (seconds) if you want to specify the approximate time of a clear vertical event for each camera
time_range_around_maxspeed = 2.0 # Search for best correlation in the range [approx_time_maxspeed - time_range_around_maxspeed, approx_time_maxspeed + time_range_around_maxspeed]
likelihood_threshold = 0.4 # Keypoints whose likelihood is below likelihood_threshold are filtered out
filter_cutoff = 6 # time series are smoothed to get coherent time-lagged correlation
Expand Down Expand Up @@ -136,7 +136,6 @@ calibration_type = 'convert' # 'convert' or 'calculate'


[triangulation]
reorder_trc = false # only checked if multi_person analysis
reproj_error_threshold_triangulation = 15 # px
likelihood_threshold_triangulation= 0.3
min_cameras_for_triangulation = 2
Expand Down Expand Up @@ -180,17 +179,11 @@ make_c3d = true # also save triangulated data in c3d format
make_c3d = true # save triangulated data in c3d format in addition to trc


[opensim]
static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']
opensim_bin_path = 'C:\OpenSim 4.4\bin'
use_augmentation = false # If using augmented measurements then set it true
load_trc_name = 'filtered' # 'default' or 'filtered', if use_augmentation = true, this line will be ignored instead using __LSTM.trc
IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]


[kinematics]
use_augmentation = true # true or false (lowercase) # Set to true if you want to use the model with augmented markers
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)
remove_individual_scaling_setup = true # true or false (lowercase) # If true, the individual scaling setup files are removed to avoid cluttering
remove_individual_IK_setup = true # true or false (lowercase) # If true, the individual IK setup files are removed to avoid cluttering



Expand All @@ -206,7 +199,7 @@ IK_timeRange = [] #left empty to IK full range or eg.[0.5,1.0]
# Check your model hierarchy with: for pre, _, node in RenderTree(model):
# print(f'{pre}{node.name} id={node.id}')
[pose.CUSTOM]
name = "CHip"
name = "Hip"
id = "19"
[[pose.CUSTOM.children]]
name = "RHip"
Expand Down
2 changes: 1 addition & 1 deletion Pose2Sim/OpenSim_Setup/Model_Pose2Sim_Coco133.osim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="40000">
<Model name="Pose2Sim_AlphaPose">
<Model name="Pose2Sim_RTMPose">
<!--The model's ground reference frame.-->
<Ground name="ground">
<!--The geometry used to display the axes of this Frame.-->
Expand Down
4 changes: 2 additions & 2 deletions Pose2Sim/OpenSim_Setup/Model_Pose2Sim_Halpe26.osim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="40000">
<Model name="Pose2Sim_AlphaPose">
<Model name="Pose2Sim_RTMPose">
<!--The model's ground reference frame.-->
<Ground name="ground">
<!--The geometry used to display the axes of this Frame.-->
Expand Down Expand Up @@ -6808,7 +6808,7 @@
<!--Path to a Component that satisfies the Socket 'parent_frame' of type PhysicalFrame (description: The frame to which this station is fixed.).-->
<socket_parent_frame>/bodyset/pelvis</socket_parent_frame>
<!--The fixed location of the station expressed in its parent frame.-->
<location>-0.063927399999999995 0 0</location>
<location>-0.063927399999999995 -0.081343112945556642 0</location>
</Marker>
<Marker name="LHip">
<!--Path to a Component that satisfies the Socket 'parent_frame' of type PhysicalFrame (description: The frame to which this station is fixed.).-->
Expand Down
2 changes: 1 addition & 1 deletion Pose2Sim/OpenSim_Setup/Model_Pose2Sim_Halpe68_136.osim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="40000">
<Model name="Pose2Sim_AlphaPose">
<Model name="Pose2Sim_RTMPose">
<!--The model's ground reference frame.-->
<Ground name="ground">
<!--The geometry used to display the axes of this Frame.-->
Expand Down
2 changes: 1 addition & 1 deletion Pose2Sim/Pose2Sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def kinematics(config=None):

end = time.time()
elapsed = end - start
logging.info(f'\nOpenSim scaling and inverse kinematics took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
logging.info(f'OpenSim scaling and inverse kinematics took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')


def runAll(config=None, do_calibration=True, do_poseEstimation=True, do_synchronization=True, do_personAssociation=True, do_triangulation=True, do_filtering=True, do_markerAugmentation=True, do_kinematics=True):
Expand Down
34 changes: 32 additions & 2 deletions Pose2Sim/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ def euclidean_distance(q1, q2):
INPUTS:
- q1: list of N_dimensional coordinates of point
or list of N points of N_dimensional coordinates
- q2: idem
OUTPUTS:
- euc_dist: float. Euclidian distance between q1 and q2
'''

q1 = np.array(q1)
Expand All @@ -233,11 +233,40 @@ def euclidean_distance(q1, q2):
dist = np.empty_like(dist)
dist[...] = np.inf

euc_dist = np.sqrt(np.nansum( [d**2 for d in dist]))
if len(dist.shape)==1:
euc_dist = np.sqrt(np.nansum( [d**2 for d in dist]))
else:
euc_dist = np.sqrt(np.nansum( [d**2 for d in dist], axis=1))

return euc_dist


def trimmed_mean(arr, trimmed_percent=0.5):
'''
Trimmed mean calculation for an array.
INPUTS:
- arr (np.array): The input array.
- trimmed_percent (float): The percentage of values to be trimmed from both ends.
OUTPUTS:
- float: The trimmed mean of the array.
'''

# Sort the array
sorted_arr = np.sort(arr)

# Determine the indices for the 25th and 75th percentiles (if trimmed_percent = 0.5)
lower_idx = int(len(sorted_arr) * (trimmed_percent/2))
upper_idx = int(len(sorted_arr) * (1 - trimmed_percent/2))

# Slice the array to exclude the 25% lowest and highest values
trimmed_arr = sorted_arr[lower_idx:upper_idx]

# Return the mean of the remaining values
return np.mean(trimmed_arr)


def world_to_camera_persp(r, t):
'''
Converts rotation R and translation T
Expand Down Expand Up @@ -364,6 +393,7 @@ def natural_sort_key(s):
Sorts list of strings with numbers in natural order (alphabetical and numerical)
Example: ['item_1', 'item_2', 'item_10', 'stuff_1']
'''
s=str(s)
return [int(c) if c.isdigit() else c.lower() for c in re.split(r'(\d+)', s)]


Expand Down
Loading

0 comments on commit 65e675a

Please sign in to comment.