@@ -117,7 +117,7 @@ def min_with_single_indices(L, T):
117
117
return minL , argminL , T_minL
118
118
119
119
120
- def sort_people (Q_kpt_old , Q_kpt , nb_persons_to_detect ):
120
+ def sort_people (Q_kpt_old , Q_kpt ):
121
121
'''
122
122
Associate persons across frames
123
123
Persons' indices are sometimes swapped when changing frame
@@ -205,6 +205,7 @@ def best_persons_and_cameras_combination(config, json_files_framef, personsIDs_c
205
205
'''
206
206
207
207
multi_person = config .get ('project' ).get ('multi_person' )
208
+ nb_persons_to_detect = config .get ('project' ).get ('nb_persons_to_detect' )
208
209
error_threshold_tracking = config .get ('personAssociation' ).get ('reproj_error_threshold_association' )
209
210
likelihood_threshold = config .get ('personAssociation' ).get ('likelihood_threshold_association' )
210
211
min_cameras_for_triangulation = config .get ('triangulation' ).get ('min_cameras_for_triangulation' )
@@ -213,7 +214,6 @@ def best_persons_and_cameras_combination(config, json_files_framef, personsIDs_c
213
214
n_cams = len (json_files_framef )
214
215
error_min = np .inf
215
216
nb_cams_off = 0 # cameras will be taken-off until the reprojection error is under threshold
216
-
217
217
errors_below_thresh = []
218
218
comb_errors_below_thresh = []
219
219
Q_kpt = []
@@ -295,39 +295,39 @@ def best_persons_and_cameras_combination(config, json_files_framef, personsIDs_c
295
295
Q_kpt = [Q_comb [np .argmin (error_comb )]]
296
296
if errors_below_thresh [0 ] < error_threshold_tracking :
297
297
break
298
-
299
- # print('\n', personsIDs_combinations)
300
- # print(errors_below_thresh)
301
- # print(comb_errors_below_thresh)
302
- # print(Q_kpt)
298
+
303
299
if multi_person :
304
- # sort combinations by error magnitude
305
- errors_below_thresh_sorted = sorted (errors_below_thresh )
306
- sorted_idx = np .array ([errors_below_thresh .index (e ) for e in errors_below_thresh_sorted ])
307
- comb_errors_below_thresh = np .array (comb_errors_below_thresh )[sorted_idx ]
308
- Q_kpt = np .array (Q_kpt )[sorted_idx ]
309
- # remove combinations with indices used several times for the same person
310
- comb_errors_below_thresh = [c .tolist () for c in comb_errors_below_thresh ]
311
- comb = comb_errors_below_thresh .copy ()
312
- comb_ok = np .array ([comb [0 ]])
313
- for i , c1 in enumerate (comb ):
314
- idx_ok = np .array ([not (common_items_in_list (c1 , c2 )) for c2 in comb [1 :]])
315
- try :
316
- comb = np .array (comb [1 :])[idx_ok ]
317
- comb_ok = np .concatenate ((comb_ok , [comb [0 ]]))
318
- except :
319
- break
320
- sorted_pruned_idx = [i for i , x in enumerate (comb_errors_below_thresh ) for c in comb_ok if np .array_equal (x ,c ,equal_nan = True )]
321
- errors_below_thresh = np .array (errors_below_thresh_sorted )[sorted_pruned_idx ].tolist ()
322
- comb_errors_below_thresh = np .array (comb_errors_below_thresh )[sorted_pruned_idx ].tolist ()
323
- Q_kpt = Q_kpt [sorted_pruned_idx ].tolist ()
300
+ if len (errors_below_thresh )> 0 :
301
+ # sort combinations by error magnitude
302
+ errors_below_thresh_sorted = sorted (errors_below_thresh )
303
+ sorted_idx = np .array ([errors_below_thresh .index (e ) for e in errors_below_thresh_sorted ])
304
+ comb_errors_below_thresh = np .array (comb_errors_below_thresh )[sorted_idx ]
305
+ Q_kpt = np .array (Q_kpt )[sorted_idx ]
306
+ # remove combinations with indices used several times for the same person
307
+ comb_errors_below_thresh = [c .tolist () for c in comb_errors_below_thresh ]
308
+ comb = comb_errors_below_thresh .copy ()
309
+ comb_ok = np .array ([comb [0 ]])
310
+ for i , c1 in enumerate (comb ):
311
+ idx_ok = np .array ([not (common_items_in_list (c1 , c2 )) for c2 in comb [1 :]])
312
+ try :
313
+ comb = np .array (comb [1 :])[idx_ok ]
314
+ comb_ok = np .concatenate ((comb_ok , [comb [0 ]]))
315
+ except :
316
+ break
317
+ sorted_pruned_idx = [i for i , x in enumerate (comb_errors_below_thresh ) for c in comb_ok if np .array_equal (x ,c ,equal_nan = True )]
318
+ errors_below_thresh = np .array (errors_below_thresh_sorted )[sorted_pruned_idx ].tolist ()
319
+ comb_errors_below_thresh = np .array (comb_errors_below_thresh )[sorted_pruned_idx ].tolist ()
320
+ Q_kpt = Q_kpt [sorted_pruned_idx ].tolist ()
324
321
325
322
# Remove indices already used for a person
326
323
personsIDs_combinations = np .array ([personsIDs_combinations [i ] for i in range (len (personsIDs_combinations ))
327
324
if not np .array (
328
325
[personsIDs_combinations [i ,j ]== comb [j ] for comb in comb_errors_below_thresh for j in range (len (comb ))]
329
326
).any ()])
330
- if len (personsIDs_combinations ) < len (errors_below_thresh ):
327
+ if len (errors_below_thresh ) >= len (personsIDs_combinations ) or len (errors_below_thresh ) >= nb_persons_to_detect :
328
+ errors_below_thresh = errors_below_thresh [:nb_persons_to_detect ]
329
+ comb_errors_below_thresh = comb_errors_below_thresh [:nb_persons_to_detect ]
330
+ Q_kpt = Q_kpt [:nb_persons_to_detect ]
331
331
break
332
332
333
333
nb_cams_off += 1
@@ -450,8 +450,6 @@ def track_2d_all(config):
450
450
json_tracked_files = [[os .path .join (poseTracked_dir , j_dir , j_file ) for j_file in json_files_names [j ]] for j , j_dir in enumerate (json_dirs_names )]
451
451
452
452
# person's tracking
453
- json_files_flatten = [item for sublist in json_files for item in sublist ]
454
- nb_persons_to_detect = max ([len (json .load (open (json_fname ))['people' ]) for json_fname in json_files_flatten ])
455
453
f_range = [[min ([len (j ) for j in json_files ])] if frame_range == [] else frame_range ][0 ]
456
454
n_cams = len (json_dirs_names )
457
455
error_min_tot , cameras_off_tot = [], []
@@ -462,7 +460,7 @@ def track_2d_all(config):
462
460
Found { len (P )} cameras in the calibration file,\
463
461
and { n_cams } cameras based on the number of pose folders.' )
464
462
465
- Q_kpt = [np .array ([0. , 0. , 0. , 1. ])] * nb_persons_to_detect
463
+ Q_kpt = [np .array ([0. , 0. , 0. , 1. ])]
466
464
for f in tqdm (range (* f_range )):
467
465
# print(f'\nFrame {f}:')
468
466
json_files_f = [json_files [c ][f ] for c in range (n_cams )]
@@ -476,8 +474,7 @@ def track_2d_all(config):
476
474
errors_below_thresh , comb_errors_below_thresh , Q_kpt = best_persons_and_cameras_combination (config , json_files_f , personsIDs_comb , P , tracked_keypoint_id , calib_params )
477
475
478
476
# reID persons across frames by checking the distance from one frame to another
479
- nb_persons_to_detect_frame = max ([len (Q_kpt_old ), len (Q_kpt )])
480
- Q_kpt , personsIDs_sorted = sort_people (Q_kpt_old , Q_kpt , nb_persons_to_detect_frame )
477
+ Q_kpt , personsIDs_sorted = sort_people (Q_kpt_old , Q_kpt )
481
478
errors_below_thresh = np .array (errors_below_thresh )[personsIDs_sorted ]
482
479
comb_errors_below_thresh = np .array (comb_errors_below_thresh )[personsIDs_sorted ]
483
480
0 commit comments