Skip to content

Commit 46172e4

Browse files
committed
Fixed previous commit
1 parent 1900705 commit 46172e4

File tree

2 files changed

+67
-67
lines changed

2 files changed

+67
-67
lines changed

Sports2D/Utilities/common.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,73 @@ def write_calibration(calib_params, toml_path):
695695
meta = '[metadata]\nadjusted = false\nerror = 0.0\n'
696696
cal_f.write(meta)
697697

698+
699+
def pad_shape(arr, target_len, fill_value=np.nan):
700+
'''
701+
Pads an array to the target length with specified fill values
702+
703+
INPUTS:
704+
- arr: Input array to be padded.
705+
- target_len: The target length of the first dimension after padding.
706+
- fill_value: The value to use for padding (default: np.nan).
707+
708+
OUTPUTS:
709+
- Padded array with shape (target_len, ...) matching the input dimensions.
710+
'''
711+
712+
if len(arr) < target_len:
713+
pad_shape = (target_len - len(arr),) + arr.shape[1:]
714+
padding = np.full(pad_shape, fill_value)
715+
return np.concatenate((arr, padding))
716+
717+
return arr
718+
719+
720+
def min_with_single_indices(L, T):
721+
'''
722+
Let L be a list (size s) with T associated tuple indices (size s).
723+
Select the smallest values of L, considering that
724+
the next smallest value cannot have the same numbers
725+
in the associated tuple as any of the previous ones.
726+
727+
Example:
728+
L = [ 20, 27, 51, 33, 43, 23, 37, 24, 4, 68, 84, 3 ]
729+
T = list(it.product(range(2),range(3)))
730+
= [(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,2),(1,3),(2,0),(2,1),(2,2),(2,3)]
731+
732+
- 1st smallest value: 3 with tuple (2,3), index 11
733+
- 2nd smallest value when excluding indices (2,.) and (.,3), i.e. [(0,0),(0,1),(0,2),X,(1,0),(1,1),(1,2),X,X,X,X,X]:
734+
20 with tuple (0,0), index 0
735+
- 3rd smallest value when excluding [X,X,X,X,X,(1,1),(1,2),X,X,X,X,X]:
736+
23 with tuple (1,1), index 5
737+
738+
INPUTS:
739+
- L: list (size s)
740+
- T: T associated tuple indices (size s)
741+
742+
OUTPUTS:
743+
- minL: list of smallest values of L, considering constraints on tuple indices
744+
- argminL: list of indices of smallest values of L (indices of best combinations)
745+
- T_minL: list of tuples associated with smallest values of L
746+
'''
747+
748+
minL = [np.nanmin(L)]
749+
argminL = [np.nanargmin(L)]
750+
T_minL = [T[argminL[0]]]
751+
752+
mask_tokeep = np.array([True for t in T])
753+
i=0
754+
while mask_tokeep.any()==True:
755+
mask_tokeep = mask_tokeep & np.array([t[0]!=T_minL[i][0] and t[1]!=T_minL[i][1] for t in T])
756+
if mask_tokeep.any()==True:
757+
indicesL_tokeep = np.where(mask_tokeep)[0]
758+
minL += [np.nanmin(np.array(L)[indicesL_tokeep]) if not np.isnan(np.array(L)[indicesL_tokeep]).all() else np.nan]
759+
argminL += [indicesL_tokeep[np.nanargmin(np.array(L)[indicesL_tokeep])] if not np.isnan(minL[-1]) else indicesL_tokeep[0]]
760+
T_minL += (T[argminL[i+1]],)
761+
i+=1
762+
763+
return np.array(minL), np.array(argminL), np.array(T_minL)
764+
698765

699766
def sort_people_sports2d(keyptpre, keypt, scores=None):
700767
'''

Sports2D/process.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -338,73 +338,6 @@ def compute_angle(ang_name, person_X_flipped, person_Y, angle_dict, keypoints_id
338338
return ang
339339

340340

341-
def min_with_single_indices(L, T):
342-
'''
343-
Let L be a list (size s) with T associated tuple indices (size s).
344-
Select the smallest values of L, considering that
345-
the next smallest value cannot have the same numbers
346-
in the associated tuple as any of the previous ones.
347-
348-
Example:
349-
L = [ 20, 27, 51, 33, 43, 23, 37, 24, 4, 68, 84, 3 ]
350-
T = list(it.product(range(2),range(3)))
351-
= [(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,2),(1,3),(2,0),(2,1),(2,2),(2,3)]
352-
353-
- 1st smallest value: 3 with tuple (2,3), index 11
354-
- 2nd smallest value when excluding indices (2,.) and (.,3), i.e. [(0,0),(0,1),(0,2),X,(1,0),(1,1),(1,2),X,X,X,X,X]:
355-
20 with tuple (0,0), index 0
356-
- 3rd smallest value when excluding [X,X,X,X,X,(1,1),(1,2),X,X,X,X,X]:
357-
23 with tuple (1,1), index 5
358-
359-
INPUTS:
360-
- L: list (size s)
361-
- T: T associated tuple indices (size s)
362-
363-
OUTPUTS:
364-
- minL: list of smallest values of L, considering constraints on tuple indices
365-
- argminL: list of indices of smallest values of L (indices of best combinations)
366-
- T_minL: list of tuples associated with smallest values of L
367-
'''
368-
369-
minL = [np.nanmin(L)]
370-
argminL = [np.nanargmin(L)]
371-
T_minL = [T[argminL[0]]]
372-
373-
mask_tokeep = np.array([True for t in T])
374-
i=0
375-
while mask_tokeep.any()==True:
376-
mask_tokeep = mask_tokeep & np.array([t[0]!=T_minL[i][0] and t[1]!=T_minL[i][1] for t in T])
377-
if mask_tokeep.any()==True:
378-
indicesL_tokeep = np.where(mask_tokeep)[0]
379-
minL += [np.nanmin(np.array(L)[indicesL_tokeep]) if not np.isnan(np.array(L)[indicesL_tokeep]).all() else np.nan]
380-
argminL += [indicesL_tokeep[np.nanargmin(np.array(L)[indicesL_tokeep])] if not np.isnan(minL[-1]) else indicesL_tokeep[0]]
381-
T_minL += (T[argminL[i+1]],)
382-
i+=1
383-
384-
return np.array(minL), np.array(argminL), np.array(T_minL)
385-
386-
387-
def pad_shape(arr, target_len, fill_value=np.nan):
388-
'''
389-
Pads an array to the target length with specified fill values
390-
391-
INPUTS:
392-
- arr: Input array to be padded.
393-
- target_len: The target length of the first dimension after padding.
394-
- fill_value: The value to use for padding (default: np.nan).
395-
396-
OUTPUTS:
397-
- Padded array with shape (target_len, ...) matching the input dimensions.
398-
'''
399-
400-
if len(arr) < target_len:
401-
pad_shape = (target_len - len(arr),) + arr.shape[1:]
402-
padding = np.full(pad_shape, fill_value)
403-
return np.concatenate((arr, padding))
404-
405-
return arr
406-
407-
408341
def draw_dotted_line(img, start, direction, length, color=(0, 255, 0), gap=7, dot_length=3, thickness=thickness):
409342
'''
410343
Draw a dotted line with on a cv2 image

0 commit comments

Comments
 (0)