From 8e7220527758507620470c779faae50a2973cf63 Mon Sep 17 00:00:00 2001 From: davidpagnon Date: Tue, 3 Sep 2024 12:31:19 +0200 Subject: [PATCH] case insensitive angles --- Sports2D/Demo/Config_demo.toml | 2 +- Sports2D/Sports2D.py | 4 ++-- Sports2D/process.py | 20 ++++++++++---------- setup.cfg | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Sports2D/Demo/Config_demo.toml b/Sports2D/Demo/Config_demo.toml index 14c587d..95f06fc 100644 --- a/Sports2D/Demo/Config_demo.toml +++ b/Sports2D/Demo/Config_demo.toml @@ -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'] diff --git a/Sports2D/Sports2D.py b/Sports2D/Sports2D.py index 69b70f1..d4483c3 100644 --- a/Sports2D/Sports2D.py +++ b/Sports2D/Sports2D.py @@ -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", diff --git a/Sports2D/process.py b/Sports2D/process.py index f5ce406..636d301 100644 --- a/Sports2D/process.py +++ b/Sports2D/process.py @@ -72,7 +72,7 @@ ## 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], @@ -80,8 +80,8 @@ '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], @@ -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], @@ -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: @@ -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 diff --git a/setup.cfg b/setup.cfg index 3effe87..3a9f7b9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = sports2d -version = 0.4.1 +version = 0.4.2 author = David Pagnon author_email = contact@david-pagnon.com description = Detect pose and compute 2D joint angles from a video.