From d39acd8a12a5505360b39129293e7305f1f38cee Mon Sep 17 00:00:00 2001 From: David PAGNON Date: Fri, 25 Oct 2024 18:48:42 +0200 Subject: [PATCH] Do not add annotation if nan in bbox --- Pose2Sim/Utilities/reproj_from_trc_calib.py | 35 ++++++++++++--------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Pose2Sim/Utilities/reproj_from_trc_calib.py b/Pose2Sim/Utilities/reproj_from_trc_calib.py index bbff3e5..182470a 100644 --- a/Pose2Sim/Utilities/reproj_from_trc_calib.py +++ b/Pose2Sim/Utilities/reproj_from_trc_calib.py @@ -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,15 +340,17 @@ 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 - labels2d_json_data['annotations'] += [{ 'keypoints': coords_list, - 'num_keypoints': num_keypoints, - 'bbox': bbox, - 'id': id, - 'image_id': file_id, - 'category_id': category_id, - 'segmentation': segmentation, - 'area': area, - 'iscrowd': iscrowd}] + + if not np.isnan(bbox).any(): + labels2d_json_data['annotations'] += [{ 'keypoints': coords_list, + 'num_keypoints': num_keypoints, + 'bbox': bbox, + 'id': id, + 'image_id': file_id, + 'category_id': category_id, + 'segmentation': segmentation, + 'area': area, + 'iscrowd': iscrowd}] with open(mmpose_json_file, 'w') as f: json.dump(labels2d_json_data, f) @@ -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]