Skip to content

Commit

Permalink
joints' coordinates saved to yarp format are now ordered following DH…
Browse files Browse the repository at this point in the history
…P19's order (#51)

Co-authored-by: “nicolocarissimi” <“[email protected]”>
  • Loading branch information
nicolocarissimi and “nicolocarissimi” authored Apr 11, 2022
1 parent ce7de49 commit a60e50c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
14 changes: 7 additions & 7 deletions datasets/dhp19/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@

DHP19_TO_HPECORE_SKELETON_IND = [
DHP19_BODY_PARTS_INDICES['head'],
DHP19_BODY_PARTS_INDICES['shoulderL'],
DHP19_BODY_PARTS_INDICES['shoulderR'],
DHP19_BODY_PARTS_INDICES['elbowL'],
DHP19_BODY_PARTS_INDICES['shoulderL'],
DHP19_BODY_PARTS_INDICES['elbowR'],
DHP19_BODY_PARTS_INDICES['handL'],
DHP19_BODY_PARTS_INDICES['handR'],
DHP19_BODY_PARTS_INDICES['elbowL'],
DHP19_BODY_PARTS_INDICES['hipL'],
DHP19_BODY_PARTS_INDICES['hipR'],
DHP19_BODY_PARTS_INDICES['kneeL'],
DHP19_BODY_PARTS_INDICES['handR'],
DHP19_BODY_PARTS_INDICES['handL'],
DHP19_BODY_PARTS_INDICES['kneeR'],
DHP19_BODY_PARTS_INDICES['footL'],
DHP19_BODY_PARTS_INDICES['footR']
DHP19_BODY_PARTS_INDICES['kneeL'],
DHP19_BODY_PARTS_INDICES['footR'],
DHP19_BODY_PARTS_INDICES['footL']
]
14 changes: 7 additions & 7 deletions datasets/h36m/utils/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@

H36M_TO_HPECORE_SKELETON_MAP = [
14, # head
17, # shoulderL
25, # shoulderR
18, # elbowL
17, # shoulderL
26, # elbowR
19, # handL
27, # handR
18, # elbowL
6, # hipL
1, # hipR
7, # kneeL
27, # handR
19, # handL
2, # kneeR
8, # footL
3 # footR
7, # kneeL
3, # footR
8 # footL
]


Expand Down
21 changes: 14 additions & 7 deletions datasets/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import numpy


class Movenet:

KEYPOINTS_COCO = ['nose', 'left_eye', 'right_eye', 'left_ear', 'right_ear',
Expand All @@ -13,21 +14,27 @@ class Movenet:

class HPECoreSkeleton:

KEYPOINTS_MAP = {'head': 0, 'left_shoulder': 1, 'right_shoulder': 2, 'left_elbow': 3, 'right_elbow': 4,
'left_wrist': 5, 'right_wrist': 6, 'left_hip': 7, 'right_hip': 8, 'left_knee': 9, 'right_knee': 10,
'left_ankle': 11, 'right_ankle': 12}
# the order of the joints is the same as the DHP19 one
# differences:
# - more descriptive labels
# - we use the more common 'wrist' and 'ankle' labels instead of DHP19's 'hand' and 'foot' ones
# - all joints are listed as first 'right' and then 'left' except for the 'hip' ones: it is not an error,
# it is DHP19's order
KEYPOINTS_MAP = {'head': 0, 'shoulder_right': 1, 'shoulder_left': 2, 'elbow_right': 3, 'elbow_left': 4,
'hip_left': 5, 'hip_right': 6, 'wrist_right': 7, 'wrist_left': 8, 'knee_right': 9, 'knee_left': 10,
'ankle_right': 11, 'ankle_left': 12}

@staticmethod
def compute_torso_sizes(skeletons: numpy.array) -> float:

if len(skeletons.shape) == 2:
l_hip = skeletons[HPECoreSkeleton.KEYPOINTS_MAP['left_hip'], :]
r_shoulder = skeletons[HPECoreSkeleton.KEYPOINTS_MAP['right_shoulder'], :]
l_hip = skeletons[HPECoreSkeleton.KEYPOINTS_MAP['hip_left'], :]
r_shoulder = skeletons[HPECoreSkeleton.KEYPOINTS_MAP['shoulder_right'], :]
torso_sizes = numpy.linalg.norm(l_hip - r_shoulder)

elif len(skeletons.shape) == 3:
l_hips = skeletons[:, HPECoreSkeleton.KEYPOINTS_MAP['left_hip'], :]
r_shoulders = skeletons[:, HPECoreSkeleton.KEYPOINTS_MAP['right_shoulder'], :]
l_hips = skeletons[:, HPECoreSkeleton.KEYPOINTS_MAP['hip_left'], :]
r_shoulders = skeletons[:, HPECoreSkeleton.KEYPOINTS_MAP['shoulder_right'], :]
torso_sizes = numpy.linalg.norm(l_hips - r_shoulders, axis=1)

return torso_sizes

0 comments on commit a60e50c

Please sign in to comment.