Skip to content

Commit

Permalink
case insensitive angles
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpagnon committed Sep 3, 2024
1 parent 385d375 commit 8e72205
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sports2D/Demo/Config_demo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fontSize = 0.3

# Select joint angles among
# ['Right ankle', 'Left ankle', 'Right knee', 'Left knee', 'Right hip', 'Left hip', 'Right shoulder', 'Left shoulder', 'Right elbow', 'Left elbow', 'Right wrist', 'Left wrist']
joint_angles = ['right ankle', 'left ankle', 'right knee', 'Left knee', 'Right hip', 'Left hip', 'Right shoulder', 'Left shoulder', 'Right elbow', 'Left elbow']
joint_angles = ['Right ankle', 'Left ankle', 'Right knee', 'Left knee', 'Right hip', 'Left hip', 'Right shoulder', 'Left shoulder', 'Right elbow', 'Left elbow']
# Select segment angles among
# ['Right foot', 'Left foot', 'Right shank', 'Left shank', 'Right thigh', 'Left thigh', 'Pelvis', 'Trunk', 'Shoulders', 'Head', 'Right arm', 'Left arm', 'Right forearm', 'Left forearm']
segment_angles = ['Right foot', 'Left foot', 'Right shank', 'Left shank', 'Right thigh', 'Left thigh', 'Pelvis', 'Trunk', 'Shoulders', 'Head', 'Right arm', 'Left arm', 'Right forearm', 'Left forearm']
Expand Down
4 changes: 2 additions & 2 deletions Sports2D/Sports2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@
'input_size': "width, height. 1280, 720 if not specified. Lower resolution will be faster but less precise",
'multiperson': "Multiperson involves tracking: will be faster if set to false. true if not specified",
'show_realtime_results': "show results in real-time. true if not specified",
'save_vid': "save video with overlaid angles. true if not specified",
'save_img': "save images with overlaid angles. true if not specified",
'save_vid': "save processed video. true if not specified",
'save_img': "save processed images. true if not specified",
'save_pose': "save pose as trc files. true if not specified",
'save_angles': "save angles as mot files. true if not specified",
'result_dir': "Current directory if not specified",
Expand Down
20 changes: 10 additions & 10 deletions Sports2D/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@


## CONSTANTS
angle_dict = {
angle_dict = { # lowercase!
# joint angles
'right ankle': [['RKnee', 'RAnkle', 'RBigToe', 'RHeel'], 'dorsiflexion', 90, 1],
'left ankle': [['LKnee', 'LAnkle', 'LBigToe', 'LHeel'], 'dorsiflexion', 90, 1],
'right knee': [['RAnkle', 'RKnee', 'RHip'], 'flexion', -180, 1],
'left knee': [['LAnkle', 'LKnee', 'LHip'], 'flexion', -180, 1],
'right hip': [['RKnee', 'RHip', 'Hip', 'Neck'], 'flexion', 0, -1],
'left hip': [['LKnee', 'LHip', 'Hip', 'Neck'], 'flexion', 0, -1],
# 'Lumbar': [['Neck', 'Hip', 'RHip', 'LHip'], 'flexion', -180, -1],
# 'Neck': [['Head', 'Neck', 'RShoulder', 'LShoulder'], 'flexion', -180, -1],
# 'lumbar': [['Neck', 'Hip', 'RHip', 'LHip'], 'flexion', -180, -1],
# 'neck': [['Head', 'Neck', 'RShoulder', 'LShoulder'], 'flexion', -180, -1],
'right shoulder': [['RElbow', 'RShoulder', 'Hip', 'Neck'], 'flexion', 0, -1],
'left shoulder': [['LElbow', 'LShoulder', 'Hip', 'Neck'], 'flexion', 0, -1],
'right elbow': [['RWrist', 'RElbow', 'RShoulder'], 'flexion', 180, -1],
Expand All @@ -96,10 +96,10 @@
'left shank': [['LAnkle', 'LKnee'], 'horizontal', 0, -1],
'right thigh': [['RKnee', 'RHip'], 'horizontal', 0, -1],
'left thigh': [['LKnee', 'LHip'], 'horizontal', 0, -1],
'Pelvis': [['LHip', 'RHip'], 'horizontal', 0, -1],
'Trunk': [['Neck', 'Hip'], 'horizontal', 0, -1],
'Shoulders': [['LShoulder', 'RShoulder'], 'horizontal', 0, -1],
'Head': [['Head', 'Neck'], 'horizontal', 0, -1],
'pelvis': [['LHip', 'RHip'], 'horizontal', 0, -1],
'trunk': [['Neck', 'Hip'], 'horizontal', 0, -1],
'shoulders': [['LShoulder', 'RShoulder'], 'horizontal', 0, -1],
'head': [['Head', 'Neck'], 'horizontal', 0, -1],
'right arm': [['RElbow', 'RShoulder'], 'horizontal', 0, -1],
'left arm': [['LElbow', 'LShoulder'], 'horizontal', 0, -1],
'right forearm': [['RWrist', 'RElbow'], 'horizontal', 0, -1],
Expand Down Expand Up @@ -332,14 +332,14 @@ def compute_angle(ang_name, person_X_flipped, person_Y, angle_dict, keypoints_id

ang_params = angle_dict.get(ang_name)
if ang_params is not None:
if ang_name in ['Pelvis', 'Trunk', 'Shoulders']:
if ang_name in ['pelvis', 'trunk', 'shoulders']:
angle_coords = [[np.abs(person_X_flipped[keypoints_ids[keypoints_names.index(kpt)]]), person_Y[keypoints_ids[keypoints_names.index(kpt)]]] for kpt in ang_params[0] if kpt in keypoints_names]
else:
angle_coords = [[person_X_flipped[keypoints_ids[keypoints_names.index(kpt)]], person_Y[keypoints_ids[keypoints_names.index(kpt)]]] for kpt in ang_params[0] if kpt in keypoints_names]
ang = points2D_to_angles(angle_coords)
ang += ang_params[2]
ang *= ang_params[3]
if ang_name in ['Pelvis', 'Shoulders']:
if ang_name in ['pelvis', 'shoulders']:
ang = ang-180 if ang>90 else ang
ang = ang+180 if ang<-90 else ang
else:
Expand Down Expand Up @@ -648,7 +648,7 @@ def draw_angles(img, valid_X, valid_Y, valid_angles, valid_X_flipped, keypoints_
ang_coords = np.array([[X[keypoints_ids[keypoints_names.index(kpt)]], Y[keypoints_ids[keypoints_names.index(kpt)]]] for kpt in ang_params[0] if kpt in keypoints_names])
X_flipped_coords = [X_flipped[keypoints_ids[keypoints_names.index(kpt)]] for kpt in ang_params[0] if kpt in keypoints_names]
flip = -1 if any(x_flipped < 0 for x_flipped in X_flipped_coords) else 1
flip = 1 if ang_name in ['Pelvis', 'Trunk', 'Shoulders'] else flip
flip = 1 if ang_name in ['pelvis', 'trunk', 'shoulders'] else flip
right_angle = True if ang_params[2]==90 else False

# Draw angle
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = sports2d
version = 0.4.1
version = 0.4.2
author = David Pagnon
author_email = [email protected]
description = Detect pose and compute 2D joint angles from a video.
Expand Down

0 comments on commit 8e72205

Please sign in to comment.