Skip to content

Commit f925289

Browse files
committed
added sections_to_keep argument (all, largest, first, last)
1 parent 9315063 commit f925289

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Sports2D/Demo/Config_demo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ correct_segment_angles_with_floor_angle = true # If the camera is tilted, correc
133133
interpolate = true
134134
interp_gap_smaller_than = 10 # do not interpolate bigger gaps
135135
fill_large_gaps_with = 'last_value' # 'last_value', 'nan', or 'zeros'
136-
136+
sections_to_keep = 'all' # 'all', 'largest', 'first', 'last'
137+
# keep 'all' valid sections even when they are interspersed with undetected chunks, or the 'largest' valid section, or the 'first' one, or the 'last' one
137138
filter = true
138139
show_graphs = true # Show plots of raw and processed results
139140
filter_type = 'butterworth' # butterworth, gaussian, LOESS, median

Sports2D/Sports2D.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
'post-processing': {'interpolate': True,
233233
'interp_gap_smaller_than': 10,
234234
'fill_large_gaps_with': 'last_value',
235+
'sections_to_keep':'all',
235236
'filter': True,
236237
'show_graphs': True,
237238
'filter_type': 'butterworth',
@@ -318,6 +319,7 @@
318319
'interpolate': ["", "interpolate missing data. true if not specified"],
319320
'interp_gap_smaller_than': ["", "interpolate sequences of missing data if they are less than N frames long. 10 if not specified"],
320321
'fill_large_gaps_with': ["", "last_value, nan, or zeros. last_value if not specified"],
322+
'sections_to_keep': ["", "all, largest, first, or last. Keep 'all' valid sections even when they are interspersed with undetected chunks, or the 'largest' valid section, or the 'first' one, or the 'last' one"],
321323
'filter': ["", "filter results. true if not specified"],
322324
'filter_type': ["", "butterworth, gaussian, median, or loess. butterworth if not specified"],
323325
'order': ["", "order of the Butterworth filter. 4 if not specified"],

Sports2D/process.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
14331433
interpolate = config_dict.get('post-processing').get('interpolate')
14341434
interp_gap_smaller_than = config_dict.get('post-processing').get('interp_gap_smaller_than')
14351435
fill_large_gaps_with = config_dict.get('post-processing').get('fill_large_gaps_with')
1436+
sections_to_keep = config_dict.get('post-processing').get('sections_to_keep')
14361437

14371438
do_filter = config_dict.get('post-processing').get('filter')
14381439
show_plots = config_dict.get('post-processing').get('show_graphs')
@@ -1514,7 +1515,7 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
15141515
if show_realtime_results:
15151516
try:
15161517
screen_width, screen_height = get_screen_size()
1517-
display_width, display_height = calculate_display_size(cam_width, cam_height, screen_width, screen_height)
1518+
display_width, display_height = calculate_display_size(cam_width, cam_height, screen_width, screen_height, margin=50)
15181519
cv2.namedWindow(f'{video_file} Sports2D', cv2.WINDOW_NORMAL)
15191520
cv2.resizeWindow(f'{video_file} Sports2D', display_width, display_height)
15201521
except: # if Pose2Sim < v0.10.29
@@ -1836,7 +1837,7 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
18361837

18371838
if fill_large_gaps_with.lower() == 'last_value':
18381839
for col in all_frames_X_person_interp.columns:
1839-
first_run_start, last_run_end = indices_of_first_last_non_nan_chunks(all_frames_Y_person_interp[col])
1840+
first_run_start, last_run_end = indices_of_first_last_non_nan_chunks(all_frames_Y_person_interp[col], min_chunk_size=interp_gap_smaller_than, chunk_choice_method=sections_to_keep)
18401841
for coord_df in [all_frames_X_person_interp, all_frames_Y_person_interp, all_frames_Z_homog]:
18411842
coord_df.loc[:first_run_start, col] = np.nan
18421843
coord_df.loc[last_run_end:, col] = np.nan
@@ -1964,7 +1965,7 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
19641965
px_to_m_i = [convert_px_to_meters(trc_data[i][kpt_name], first_person_height, height_px, cx, cy, -floor_angle_estim, visible_side=visible_side_i) for kpt_name in new_keypoints_names]
19651966
trc_data_m_i = pd.concat([all_frames_time.rename('time')]+px_to_m_i, axis=1)
19661967
for c in 3*np.arange(len(trc_data_m_i.columns[3::3]))+1: # only X coordinates
1967-
first_run_start, last_run_end = indices_of_first_last_non_nan_chunks(trc_data_m_i.iloc[:,c])
1968+
first_run_start, last_run_end = indices_of_first_last_non_nan_chunks(trc_data_m_i.iloc[:,c], min_chunk_size=interp_gap_smaller_than, chunk_choice_method=sections_to_keep)
19681969
trc_data_m_i.iloc[:first_run_start,c+2] = np.nan
19691970
trc_data_m_i.iloc[last_run_end:,c+2] = np.nan
19701971
trc_data_m_i.iloc[first_run_start:last_run_end,c+2] = trc_data_m_i.iloc[first_run_start:last_run_end,c+2].ffill().bfill()
@@ -2065,7 +2066,7 @@ def process_fun(config_dict, video_file, time_range, frame_rate, result_dir):
20652066
all_frames_angles_person_interp = all_frames_angles_person.apply(interpolate_zeros_nans, axis=0, args = [interp_gap_smaller_than, 'linear'])
20662067
if fill_large_gaps_with == 'last_value':
20672068
for col in all_frames_angles_person_interp.columns:
2068-
first_run_start, last_run_end = indices_of_first_last_non_nan_chunks(all_frames_angles_person_interp[col])
2069+
first_run_start, last_run_end = indices_of_first_last_non_nan_chunks(all_frames_angles_person_interp[col], min_chunk_size=interp_gap_smaller_than, chunk_choice_method=sections_to_keep)
20692070
all_frames_angles_person_interp.loc[:first_run_start, col] = np.nan
20702071
all_frames_angles_person_interp.loc[last_run_end:, col] = np.nan
20712072
all_frames_angles_person_interp.loc[first_run_start:last_run_end, col] = all_frames_angles_person_interp.loc[first_run_start:last_run_end, col].ffill().bfill()

0 commit comments

Comments
 (0)