Skip to content

Commit 62984f4

Browse files
committed
fixed problems raised by tests
1 parent e36d2c6 commit 62984f4

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

Sports2D/Utilities/tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,18 @@ def test_workflow():
9696

9797
# With no pixels to meters conversion, one person to select, lightweight mode, detection frequency, slowmo factor, gaussian filter, RTMO body pose model
9898
demo_cmd3 = ["sports2d", "--show_realtime_results", "False", "--show_graphs", "False", "--save_graphs", "False",
99-
# "--calib_file", "calib_demo.toml",
99+
"--floor_angle", "from_calib", "--xy_origin", "from_calib", "--perspective_unit", "from_calib", "--calib_file", os.path.join(root_dir, "demo_Sports2D", "demo_Sports2D_calib.toml"),
100100
"--nb_persons_to_detect", "1", "--person_ordering_method", "greatest_displacement",
101101
"--mode", "lightweight", "--det_frequency", "50",
102102
"--slowmo_factor", "4",
103103
"--filter_type", "gaussian", "--use_augmentation", "False",
104104
"--pose_model", "body", "--mode", """{'pose_class':'RTMO', 'pose_model':'https://download.openmmlab.com/mmpose/v1/projects/rtmo/onnx_sdk/rtmo-m_16xb16-600e_body7-640x640-39e78cc4_20231211.zip', 'pose_input_size':[640, 640]}"""]
105105
subprocess.run(demo_cmd3, check=True, capture_output=True, text=True, encoding='utf-8', errors='replace')
106106

107-
# With a time range, inverse kinematics, marker augmentation
107+
# With a time range, inverse kinematics, marker augmentation, perspective value in fov
108108
demo_cmd4 = ["sports2d", "--person_ordering_method", "greatest_displacement", "--show_realtime_results", "False", "--show_graphs", "False", "--save_graphs", "False",
109109
"--time_range", "1.2", "2.7",
110+
"--perspective_value", "40", "--perspective_unit", "fov_deg",
110111
"--do_ik", "True", "--use_augmentation", "True",
111112
"--nb_persons_to_detect", "all", "--first_person_height", "1.65",
112113
"--visible_side", "auto", "front", "--participant_mass", "55.0", "67.0"]

Sports2D/process.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,40 +1438,41 @@ def get_floor_params(floor_angle='auto', xy_origin=['auto'],
14381438
xy_origin_calib = [cx, cy]
14391439

14401440
# Estimate xy_origin from the line formed by the toes when they are on the ground (where speed = 0)
1441-
if floor_angle in ['auto', 'from_kinematics'] or xy_origin in [['auto'], ['from_kinematics']]:
1442-
px_per_m = height_px/height_m
1443-
toe_speed_below_px_frame = toe_speed_below * px_per_m / fps # speed below which the foot is considered to be stationary
1444-
try:
1445-
if all(key in trc_data for key in ['LBigToe', 'RBigToe']):
1446-
floor_angle_kin, xy_origin_kin, gait_direction = compute_floor_line(trc_data, score_data, keypoint_names=['LBigToe', 'RBigToe'], toe_speed_below=toe_speed_below_px_frame, score_threshold=score_threshold)
1447-
else:
1448-
floor_angle_kin, xy_origin_estim, gait_direction = compute_floor_line(trc_data, score_data, keypoint_names=['LAnkle', 'RAnkle'], toe_speed_below=toe_speed_below_px_frame, score_threshold=score_threshold)
1449-
xy_origin_kin[1] = xy_origin_kin[1] + 0.13*px_per_m # approx. height of the ankle above the floor
1450-
logging.warning(f'The RBigToe and LBigToe are missing from your pose estimation model. Using ankles - 13 cm to compute the floor line.')
1451-
except:
1452-
floor_angle_kin = 0
1453-
xy_origin_kin = cam_width/2, cam_height/2
1454-
logging.warning(f'Could not estimate the floor angle and xy_origin from person {0}. Make sure that the full body is visible. Using floor angle = 0° and xy_origin = [{cam_width/2}, {cam_height/2}] px.')
1441+
px_per_m = height_px/height_m
1442+
toe_speed_below_px_frame = toe_speed_below * px_per_m / fps # speed below which the foot is considered to be stationary
1443+
try:
1444+
if all(key in trc_data for key in ['LBigToe', 'RBigToe']):
1445+
floor_angle_kin, xy_origin_kin, gait_direction = compute_floor_line(trc_data, score_data, keypoint_names=['LBigToe', 'RBigToe'], toe_speed_below=toe_speed_below_px_frame, score_threshold=score_threshold)
1446+
else:
1447+
floor_angle_kin, xy_origin_estim, gait_direction = compute_floor_line(trc_data, score_data, keypoint_names=['LAnkle', 'RAnkle'], toe_speed_below=toe_speed_below_px_frame, score_threshold=score_threshold)
1448+
xy_origin_kin[1] = xy_origin_kin[1] + 0.13*px_per_m # approx. height of the ankle above the floor
1449+
logging.warning(f'The RBigToe and LBigToe are missing from your pose estimation model. Using ankles - 13 cm to compute the floor line.')
1450+
except:
1451+
floor_angle_kin = 0
1452+
xy_origin_kin = cam_width/2, cam_height/2
1453+
logging.warning(f'Could not estimate the floor angle and xy_origin from person {0}. Make sure that the full body is visible. Using floor angle = 0° and xy_origin = [{cam_width/2}, {cam_height/2}] px.')
14551454

14561455
# Determine final floor angle estimation
14571456
if floor_angle == 'from_calib':
14581457
floor_angle_estim = floor_angle_calib
14591458
elif floor_angle in ['auto', 'from_kinematics']:
14601459
floor_angle_estim = floor_angle_kin
1461-
elif isinstance(floor_angle, (int,float)):
1462-
floor_angle_estim = np.radians(floor_angle)
14631460
else:
1464-
raise ValueError(f'Invalid floor_angle: {floor_angle}. Must be "auto", "from_calib", "from_kinematics", or a numeric value in degrees.')
1461+
try:
1462+
floor_angle_estim = np.radians(float(floor_angle))
1463+
except:
1464+
raise ValueError(f'Invalid floor_angle: {floor_angle}. Must be "auto", "from_calib", "from_kinematics", or a numeric value in degrees.')
14651465

14661466
# Determine final xy_origin estimation
14671467
if xy_origin == ['from_calib']:
14681468
xy_origin_estim = xy_origin_calib
14691469
elif xy_origin in [['auto'], ['from_kinematics']]:
14701470
xy_origin_estim = xy_origin_kin
1471-
elif all(isinstance(o, (int,float)) for o in xy_origin) and len(xy_origin) == 2:
1472-
xy_origin_estim = xy_origin
14731471
else:
1474-
raise ValueError(f'Invalid xy_origin: {xy_origin}. Must be "auto", "from_calib", "from_kinematics", or a list of two numeric values in pixels.')
1472+
try:
1473+
xy_origin_estim = [float(v) for v in xy_origin]
1474+
except:
1475+
raise ValueError(f'Invalid xy_origin: {xy_origin}. Must be "auto", "from_calib", "from_kinematics", or a list of two numeric values in pixels.')
14751476

14761477
return floor_angle_estim, xy_origin_estim, gait_direction
14771478

@@ -1653,7 +1654,7 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
16531654
if calib_file == '':
16541655
calib_file = None
16551656
else:
1656-
calib_file = video_dir / calib_file
1657+
calib_file = Path(calib_file).resolve()
16571658
if not calib_file.is_file():
16581659
raise FileNotFoundError(f'Error: Could not find calibration file {calib_file}. Check that the file exists.')
16591660

0 commit comments

Comments
 (0)