Skip to content

Commit 4c52de8

Browse files
committed
shorter key available (-i instead of --video_input)
1 parent 9bdd7af commit 4c52de8

File tree

3 files changed

+57
-51
lines changed

3 files changed

+57
-51
lines changed

Sports2D/Demo/Config_demo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ keypoint_number_threshold = 0.3 # Person will be ignored if the number of good k
5151

5252

5353
[angles]
54-
display_angle_values_on = ['body','list'] # 'body', 'list', ['body', 'list'], []. Display angle values on the body, as a list in the upper left of the image, both, or do not display them.
54+
display_angle_values_on = ['body','list'] # 'body', 'list', ['body', 'list'], None. Display angle values on the body, as a list in the upper left of the image, both, or do not display them.
5555
fontSize = 0.3
5656

5757
# Select joint angles among
@@ -71,7 +71,7 @@ interp_gap_smaller_than = 10 # do not interpolate bigger gaps
7171
fill_large_gaps_with = 'last_value' # 'last_value', 'nan', or 'zeros'
7272

7373
filter = true
74-
show_plots = true # Crashes on the third opened window...
74+
show_graphs = true # Show plots of raw and processed results
7575
filter_type = 'butterworth' # butterworth, gaussian, LOESS, median
7676
[post-processing.butterworth]
7777
order = 4

Sports2D/Sports2D.py

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
'interp_gap_smaller_than': 10,
176176
'fill_large_gaps_with': 'last_value',
177177
'filter': True,
178-
'show_plots': True,
178+
'show_graphs': True,
179179
'filter_type': 'butterworth',
180180
'butterworth': {'order': 4, 'cut_off_frequency': 3},
181181
'gaussian': {'sigma_kernel': 1},
@@ -184,43 +184,43 @@
184184
}
185185
}
186186

187-
CONFIG_HELP = {'config': "Path to a toml configuration file",
188-
'video_input': "webcam, or video_path.mp4, or video1_path.avi video2_path.mp4 ... Beware that images won't be saved if paths contain non ASCII characters",
189-
'time_range': "start_time, end_time. In seconds. Whole video if not specified",
190-
'video_dir': "Current directory if not specified",
191-
'webcam_id': "webcam ID. 0 if not specified",
192-
'input_size': "width, height. 1280, 720 if not specified. Lower resolution will be faster but less precise",
193-
'multiperson': "Multiperson involves tracking: will be faster if set to false. true if not specified",
194-
'show_realtime_results': "show results in real-time. true if not specified",
195-
'save_vid': "save processed video. true if not specified",
196-
'save_img': "save processed images. true if not specified",
197-
'save_pose': "save pose as trc files. true if not specified",
198-
'save_angles': "save angles as mot files. true if not specified",
199-
'result_dir': "Current directory if not specified",
200-
'pose_model': "Only body_with_feet is available for now. body_with_feet if not specified",
201-
'mode': "light, balanced, or performance. balanced if not specified",
202-
'det_frequency': "Run person detection only every N frames, and inbetween track previously detected bounding boxes. keypoint detection is still run on all frames.\n\
203-
Equal to or greater than 1, can be as high as you want in simple uncrowded cases. Much faster, but might be less accurate. 1 if not specified: detection runs on all frames",
204-
'tracking_mode': "sports2d or rtmlib. sports2d is generally much more accurate and comparable in speed. sports2d if not specified",
205-
'keypoint_likelihood_threshold': "Detected keypoints are not retained if likelihood is below this threshold. 0.3 if not specified",
206-
'average_likelihood_threshold': "Detected persons are not retained if average keypoint likelihood is below this threshold. 0.5 if not specified",
207-
'keypoint_number_threshold': "Detected persons are not retained if number of detected keypoints is below this threshold. 0.3 if not specified, i.e., i.e., 30 percent",
208-
'display_angle_values_on': "body, list, or body list. body list if not specified",
209-
'fontSize': "Font size for angle values. 0.3 if not specified",
210-
'joint_angles': '"Right ankle" "Left ankle" "Right knee" "Left knee" "Right hip" "Left hip" "Right shoulder" "Left shoulder" "Right elbow" "Left elbow" if not specified',
211-
'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" if not specified',
212-
'flip_left_right': "true or false. true to get consistent angles with people facing both left and right sides. Set it to false if you want timeseries to be continuous even when the participent switches their stance. true if not specified",
213-
'interpolate': "Interpolate missing data. true if not specified",
214-
'interp_gap_smaller_than': "Interpolate sequences of missing data if they are less than N frames long. 10 if not specified",
215-
'fill_large_gaps_with': "last_value, nan, or zeros. last_value if not specified",
216-
'filter': "Filter results. true if not specified",
217-
'show_plots': "Show plots. true if not specified",
218-
'filter_type': "butterworth, gaussian, median, or loess. butterworth if not specified",
219-
'order': "Order of the Butterworth filter. 4 if not specified",
220-
'cut_off_frequency': "Cut-off frequency of the Butterworth filter. 3 if not specified",
221-
'sigma_kernel': "Sigma of the gaussian filter. 1 if not specified",
222-
'nb_values_used': "Number of values used for the loess filter. 5 if not specified",
223-
'kernel_size': "Kernel size of the median filter. 3 if not specified"
187+
CONFIG_HELP = {'config': ["c", "Path to a toml configuration file"],
188+
'video_input': ["i", "webcam, or video_path.mp4, or video1_path.avi video2_path.mp4 ... Beware that images won't be saved if paths contain non ASCII characters"],
189+
'webcam_id': ["w", "webcam ID. 0 if not specified"],
190+
'time_range': ["t", "start_time, end_time. In seconds. Whole video if not specified"],
191+
'video_dir': ["d", "Current directory if not specified"],
192+
'result_dir': ["r", "Current directory if not specified"],
193+
'show_realtime_results': ["R", "show results in real-time. true if not specified"],
194+
'display_angle_values_on': ["a", '"body", "list", "body" "list", or "None". body list if not specified'],
195+
'show_graphs': ["G", "Show plots of raw and processed results. true if not specified"],
196+
'joint_angles': ["j", '"Right ankle" "Left ankle" "Right knee" "Left knee" "Right hip" "Left hip" "Right shoulder" "Left shoulder" "Right elbow" "Left elbow" if not specified'],
197+
'segment_angles': ["s", '"Right foot" "Left foot" "Right shank" "Left shank" "Right thigh" "Left thigh" "Pelvis" "Trunk" "Shoulders" "Head" "Right arm" "Left arm" "Right forearm" "Left forearm" if not specified'],
198+
'save_vid': ["V", "save processed video. true if not specified"],
199+
'save_img': ["I", "save processed images. true if not specified"],
200+
'save_pose': ["P", "save pose as trc files. true if not specified"],
201+
'save_angles': ["A", "save angles as mot files. true if not specified"],
202+
'pose_model': ["p", "Only body_with_feet is available for now. body_with_feet if not specified"],
203+
'mode': ["m", "light, balanced, or performance. balanced if not specified"],
204+
'det_frequency': ["f", "Run person detection only every N frames, and inbetween track previously detected bounding boxes. keypoint detection is still run on all frames.\n\
205+
Equal to or greater than 1, can be as high as you want in simple uncrowded cases. Much faster, but might be less accurate. 1 if not specified: detection runs on all frames"],
206+
'multiperson': ["M", "Multiperson involves tracking: will be faster if set to false. true if not specified"],
207+
'tracking_mode': ["", "sports2d or rtmlib. sports2d is generally much more accurate and comparable in speed. sports2d if not specified"],
208+
'input_size': ["", "width, height. 1280, 720 if not specified. Lower resolution will be faster but less precise"],
209+
'keypoint_likelihood_threshold': ["", "Detected keypoints are not retained if likelihood is below this threshold. 0.3 if not specified"],
210+
'average_likelihood_threshold': ["", "Detected persons are not retained if average keypoint likelihood is below this threshold. 0.5 if not specified"],
211+
'keypoint_number_threshold': ["", "Detected persons are not retained if number of detected keypoints is below this threshold. 0.3 if not specified, i.e., i.e., 30 percent"],
212+
'fontSize': ["", "Font size for angle values. 0.3 if not specified"],
213+
'flip_left_right': ["", "true or false. true to get consistent angles with people facing both left and right sides. Set it to false if you want timeseries to be continuous even when the participent switches their stance. true if not specified"],
214+
'interpolate': ["", "Interpolate missing data. true if not specified"],
215+
'interp_gap_smaller_than': ["", "Interpolate sequences of missing data if they are less than N frames long. 10 if not specified"],
216+
'fill_large_gaps_with': ["", "last_value, nan, or zeros. last_value if not specified"],
217+
'filter': ["", "Filter results. true if not specified"],
218+
'filter_type': ["", "butterworth, gaussian, median, or loess. butterworth if not specified"],
219+
'order': ["", "Order of the Butterworth filter. 4 if not specified"],
220+
'cut_off_frequency': ["", "Cut-off frequency of the Butterworth filter. 3 if not specified"],
221+
'sigma_kernel': ["", "Sigma of the gaussian filter. 1 if not specified"],
222+
'nb_values_used': ["", "Number of values used for the loess filter. 5 if not specified"],
223+
'kernel_size': ["", "Kernel size of the median filter. 3 if not specified"]
224224
}
225225

226226

@@ -415,16 +415,19 @@ def main():
415415

416416
# Dynamically add arguments for each leaf key in the DEFAULT_CONFIG
417417
parser = argparse.ArgumentParser(description="Use sports2d to compute your athlete's pose, joint, and segment angles. See https://github.com/davidpagnon/Sports2D")
418-
parser.add_argument('--config', type=str, required=False, help='Path to a toml configuration file')
418+
parser.add_argument('-C', '--config', type=str, required=False, help='Path to a toml configuration file')
419+
419420
leaf_keys = get_leaf_keys(DEFAULT_CONFIG)
420-
for key in leaf_keys:
421-
leaf_name = key.split('.')[-1]
422-
if type(leaf_keys[key]) == bool:
423-
parser.add_argument(f'--{leaf_name}', type=str2bool, help=CONFIG_HELP[leaf_name])
424-
elif type(leaf_keys[key]) == list:
425-
parser.add_argument(f'--{leaf_name}', type=type(leaf_keys[key][0]), nargs='*', help=CONFIG_HELP[leaf_name])
421+
leaf_keys = {k.split('.')[-1]:v for k,v in leaf_keys.items()}
422+
for leaf_name in list(CONFIG_HELP.keys())[1:]:
423+
short_key = CONFIG_HELP[leaf_name][0]
424+
arg_str = [f'-{short_key}', f'--{leaf_name}'] if short_key else [f'--{leaf_name}']
425+
if type(leaf_keys[leaf_name]) == bool:
426+
parser.add_argument(*arg_str, type=str2bool, help=CONFIG_HELP[leaf_name][1])
427+
elif type(leaf_keys[leaf_name]) == list:
428+
parser.add_argument(*arg_str, type=type(leaf_keys[leaf_name][0]), nargs='*', help=CONFIG_HELP[leaf_name][1])
426429
else:
427-
parser.add_argument(f'--{leaf_name}', type=type(leaf_keys[key]), help=CONFIG_HELP[leaf_name])
430+
parser.add_argument(*arg_str, type=type(leaf_keys[leaf_name]), help=CONFIG_HELP[leaf_name][1])
428431
args = parser.parse_args()
429432

430433
# If config.toml file is provided, load it, else, use default config

Sports2D/process.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,16 @@ def draw_angles(img, valid_X, valid_Y, valid_angles, valid_X_flipped, keypoints_
652652
right_angle = True if ang_params[2]==90 else False
653653

654654
# Draw angle
655+
if len(ang_coords) == 2: # segment angle
656+
app_point, vec = draw_segment_angle(img, ang_coords, flip)
657+
else: # joint angle
658+
app_point, vec1, vec2 = draw_joint_angle(img, ang_coords, flip, right_angle)
659+
660+
# Write angle on body
655661
if 'body' in display_angle_values_on:
656662
if len(ang_coords) == 2: # segment angle
657-
app_point, vec = draw_segment_angle(img, ang_coords, flip)
658663
write_angle_on_body(img, ang, app_point, vec, np.array([1,0]), dist=20, color=(255,255,255), fontSize=fontSize, thickness=thickness)
659-
660664
else: # joint angle
661-
app_point, vec1, vec2 = draw_joint_angle(img, ang_coords, flip, right_angle)
662665
write_angle_on_body(img, ang, app_point, vec1, vec2, dist=40, color=(0,255,0), fontSize=fontSize, thickness=thickness)
663666

664667
# Write angle as a list on image with progress bar

0 commit comments

Comments
 (0)