Do not add annotation if nan in bbox

This commit is contained in:
David PAGNON 2024-10-25 18:48:42 +02:00 committed by GitHub
parent f6c49e011e
commit d39acd8a12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -321,13 +321,12 @@ def dataset_to_mmpose2d(coords_df, mmpose_json_file, img_size, markerset='custom
for marker in marker_list:
# visibility: 2 visible, 1 occluded, 0 out of frame
coords_mk = coords.loc[coords.index.get_level_values(2)==marker]
coords_list += [0.0, 0.0, 0] if np.isnan(coords_mk).any() else coords_mk.tolist()+[2]
coords_list += coords_mk.tolist()+[2] if not np.isnan(coords_mk).any() else [0.0, 0.0, 0]
# bbox
min_x = np.nanmin(coords.loc[coords.index.get_level_values(3)=='x'])
min_y = np.nanmin(coords.loc[coords.index.get_level_values(3)=='y'])
max_x = np.nanmax(coords.loc[coords.index.get_level_values(3)=='x'])
max_y = np.nanmax(coords.loc[coords.index.get_level_values(3)=='y'])
x_coords = coords.loc[coords.index.get_level_values(3)=='x']
y_coords = coords.loc[coords.index.get_level_values(3)=='y']
min_x, min_y, max_x, max_y = np.nanmin(x_coords), np.nanmin(y_coords), np.nanmax(x_coords), np.nanmax(y_coords)
bbox = [min_x, min_y, max_x, max_y]
# bbox_width = max_x - min_x
# bbox_height = max_y - min_y
@ -341,6 +340,8 @@ def dataset_to_mmpose2d(coords_df, mmpose_json_file, img_size, markerset='custom
segmentation = []
area = 0
iscrowd = 0 # 1 if len(persons)>1 else 0
if not np.isnan(bbox).any():
labels2d_json_data['annotations'] += [{ 'keypoints': coords_list,
'num_keypoints': num_keypoints,
'bbox': bbox,
@ -418,7 +419,7 @@ def reproj_from_trc_calib_func(**args):
num_frames = [len(data_trc) if P_all.shape[1]==1 else min(P_all.shape[1], len(data_trc))][0]
columns_iterables = [['DavidPagnon'], ['person0'], bodyparts, ['x','y']]
columns_h5 = pd.MultiIndex.from_product(columns_iterables, names=['scorer', 'individuals', 'bodyparts', 'coords'])
rows_iterables = [[os.path.join(os.path.splitext(input_trc_file)[0],f'img_{i:03d}.png') for i in range(num_frames)]]
rows_iterables = [[os.path.join(os.path.splitext(input_trc_file)[0],f'img_{i:03d}.jpg') for i in range(num_frames)]]
rows_h5 = pd.MultiIndex.from_product(rows_iterables)
data_h5 = pd.DataFrame(np.nan, index=rows_h5, columns=columns_h5)
@ -436,6 +437,10 @@ def reproj_from_trc_calib_func(**args):
y_all = [coords_2D_all[i][0,0,1] for i in range(len(P_all_frame))]
else:
x_all, y_all = reprojection(P_all_frame, q)
# Store with one single decimal
x_all = np.round(np.array(x_all), decimals=1)
y_all = np.round(np.array(y_all), decimals=1)
[coords[cam].extend([x_all[cam], y_all[cam]]) for cam in range(len(P_all_frame))]
for cam in range(len(P_all_frame)):
data_proj[cam].iloc[frame,:] = coords[cam]