|
1152 | 1152 | },
|
1153 | 1153 | "outputs": [],
|
1154 | 1154 | "source": [
|
1155 |
| - "if agg_features:\n", |
| 1155 | + "if not agg_features.empty:\n", |
1156 | 1156 | " for group_name, df in tqdm.tqdm(agg_features.groupby(\"detection_classes_names\")):\n",
|
1157 |
| - " os.makedirs(f'{output_dir}/{group_name}', exist_ok=True)\n", |
1158 |
| - "\n", |
1159 |
| - " for row in df.itertuples(index=False):\n", |
1160 |
| - " image = cv2.imread(os.path.join(images_dir,row.image_name))\n", |
1161 |
| - " image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n", |
1162 |
| - " new_h, new_w = image.shape[0], image.shape[1]\n", |
1163 |
| - " y1, x1, y2, x2 = row.bbox_0, row.bbox_1, row.bbox_2, row.bbox_3\n", |
1164 |
| - " new_bbox = resize_bbox(y1, x1, y2, x2, HEIGHT_TRACKING, WIDTH_TRACKING, new_h, new_w)\n", |
1165 |
| - " name = f'{os.path.splitext(row.image_name)[0]}_{row.particle}.png'\n", |
1166 |
| - " cv2.imwrite(f'{output_dir}/{row.detection_classes_names}/{name}', image[new_bbox[0]:new_bbox[2], new_bbox[1]:new_bbox[3]])" |
| 1157 | + " os.makedirs(f'{output_dir}/{group_name}', exist_ok=True)\n", |
| 1158 | + "\n", |
| 1159 | + " for row in df.itertuples(index=False):\n", |
| 1160 | + " image = cv2.imread(os.path.join(images_dir,row.image_name))\n", |
| 1161 | + " image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n", |
| 1162 | + " new_h, new_w = image.shape[0], image.shape[1]\n", |
| 1163 | + " y1, x1, y2, x2 = row.bbox_0, row.bbox_1, row.bbox_2, row.bbox_3\n", |
| 1164 | + " new_bbox = resize_bbox(y1, x1, y2, x2, HEIGHT_TRACKING, WIDTH_TRACKING, new_h, new_w)\n", |
| 1165 | + " name = f'{os.path.splitext(row.image_name)[0]}_{row.particle}.png'\n", |
| 1166 | + " cv2.imwrite(f'{output_dir}/{row.detection_classes_names}/{name}', image[new_bbox[0]:new_bbox[2], new_bbox[1]:new_bbox[3]])" |
1167 | 1167 | ]
|
1168 | 1168 | },
|
1169 | 1169 | {
|
|
0 commit comments