This commit is contained in:
davidpagnon 2024-03-20 14:16:38 +01:00
parent c4773faa68
commit 2bb5bbbc4b
3 changed files with 7305 additions and 13 deletions

File diff suppressed because it is too large Load Diff

View File

@ -234,6 +234,33 @@ plt.legend()
plt.show()
# # Refine synchronization offset
# offset = []
# for cam_id in cam_list:
# coords_nb = int(len(df_coords[cam_id].columns)/2)
# lag_range = min(int(ref_frame_nb/2), fps)
# offset_cam, corr_cam = [], []
# for coord_id in range(coords_nb):
# camx = df_speed[ref_cam_id][coord_id][search_sync_around_frame[ref_cam_id][0]:search_sync_around_frame[ref_cam_id][1]]
# camy = df_speed[cam_id][coord_id][search_sync_around_frame[cam_id][0]:search_sync_around_frame[cam_id][1]]
# offset_cam_coord, corr_cam_coord = time_lagged_cross_corr(camx, camy, lag_range, show=False)
# offset_cam.append(offset_cam_coord)
# corr_cam.append(corr_cam_coord)
# # print(f'{coord_id} keypoint: offset = {offset_cam} frames and correlation = {corr_cam}.')
# corr_cam = np.array(corr_cam)
# offset_cam = np.array(offset_cam)
# # take highest correlations and retrieve median offset
# top_five_offset_coord = np.argpartition(-corr_cam, top_N_corr)[:top_N_corr]
# top_five_offset_coord = top_five_offset_coord[np.argsort(corr_cam[top_five_offset_coord])][::-1]
# top_five_corr_coord = corr_cam[top_five_offset_coord]
# top_five_offset_coord = [c for i,c in enumerate(top_five_offset_coord) if top_five_corr_coord[i]>corr_threshold]
# best_offset_cam = round(np.median(offset_cam[top_five_offset_coord]))
# print('\n', best_offset_cam, offset_cam[top_five_offset_coord], corr_cam[top_five_offset_coord])
# offset.append(best_offset_cam)
# print(offset)
for json_dir in json_dirs:
old_file_names = fnmatch.filter(os.listdir(os.path.join(json_dir)), '*.json.old')
for old in old_file_names:

View File

@ -12,7 +12,7 @@
- no ref cam (least amount of frames), no kpt selection
- recap
- whole sequence or around approx time (if long)
- somehow fix demo (offset 0 frames when 0 frames offset)
- somehow fix demo (offset 0 frames when 0 frames offset, right now [0,-2,-2]) -> min_conf = 0.4 (check problem with 0.0)
@ -52,18 +52,18 @@ __status__ = "Development"
# FUNCTIONS
def convert_json2pandas(json_dir):
def convert_json2pandas(json_dir, min_conf=0.6):
'''
Convert JSON files in a directory to a pandas DataFrame.
INPUTS:
- json_dir: str. The directory path containing the JSON files.
- min_conf: float. Drop values if confidence is below min_conf.
OUTPUT:
- df_json_coords: dataframe. Extracted coordinates in a pandas dataframe.
'''
min_conf = 0.6
nb_coord = 25 # int(len(json_data)/3)
json_files_names = fnmatch.filter(os.listdir(os.path.join(json_dir)), '*.json') # modified ( 'json' to '*.json' )
json_files_names = sort_stringlist_by_last_number(json_files_names)
@ -386,11 +386,12 @@ def synchronize_cams_all(config_dict):
fps = config_dict.get('project').get('frame_rate')
reset_sync = config_dict.get('synchronization').get('reset_sync')
approx_time_maxspeed = config_dict.get('synchronization').get('approx_time_maxspeed')
min_conf = 0.4
filter_order = 4
filter_cutoff = 6
# vmax = 4 # px/s # in average for each keypoint -> vmax sum = 100 px/s
corr_threshold = 0.8
top_N_corr = 10
# corr_threshold = 0.8
# top_N_corr = 10
# List json files
pose_listdirs_names = next(os.walk(pose_dir))[1]
@ -403,7 +404,7 @@ def synchronize_cams_all(config_dict):
df_coords = []
b, a = signal.butter(filter_order/2, filter_cutoff/(fps/2), 'low', analog = False)
for i, json_dir in enumerate(json_dirs):
df_coords.append(convert_json2pandas(json_dir))
df_coords.append(convert_json2pandas(json_dir, min_conf=min_conf))
df_coords[i] = drop_col(df_coords[i],3) # drop likelihood
df_coords[i] = df_coords[i].apply(interpolate_zeros_nans, axis=0, args = ['linear'])
df_coords[i] = df_coords[i].bfill().ffill()
@ -472,7 +473,8 @@ def synchronize_cams_all(config_dict):
# Refine synchronization offset
# Refine synchronization offset: -> not needed
# Time-lagged cross-correlation for each keypoint, select top N highest correlations, take median offset
offset = []
for cam_id in cam_list:
coords_nb = int(len(df_coords[cam_id].columns)/2)
@ -500,12 +502,6 @@ def synchronize_cams_all(config_dict):
# def best_synchronization_offset(df_coords, fps, approx_time_maxspeed):
# '''
# '''
# pass
# test time-lagged c-c for sum_speeds
search_sync_min_frame_nb = min([(s[1]-s[0]) for s in search_sync_around_frame])