|
1 | 1 | # Copyright (c) OpenMMLab. All rights reserved.
|
2 | 2 | import copy
|
| 3 | +import warnings |
3 | 4 | from typing import List, Optional, Tuple, Union
|
4 | 5 |
|
5 | 6 | import numpy as np
|
6 | 7 | from nuscenes import NuScenes
|
7 | 8 | from nuscenes.utils.geometry_utils import view_points
|
8 | 9 | from pyquaternion import Quaternion
|
9 | 10 | from shapely.geometry import MultiPoint, box
|
| 11 | +from shapely.geometry.polygon import Polygon |
10 | 12 |
|
11 | 13 | from mmdet3d.structures import Box3DMode, CameraInstance3DBoxes, points_cam2img
|
12 | 14 | from mmdet3d.structures.ops import box_np_ops
|
@@ -358,15 +360,17 @@ def post_process_coords(
|
358 | 360 |
|
359 | 361 | if polygon_from_2d_box.intersects(img_canvas):
|
360 | 362 | img_intersection = polygon_from_2d_box.intersection(img_canvas)
|
361 |
| - intersection_coords = np.array( |
362 |
| - [coord for coord in img_intersection.exterior.coords]) |
363 |
| - |
364 |
| - min_x = min(intersection_coords[:, 0]) |
365 |
| - min_y = min(intersection_coords[:, 1]) |
366 |
| - max_x = max(intersection_coords[:, 0]) |
367 |
| - max_y = max(intersection_coords[:, 1]) |
368 |
| - |
369 |
| - return min_x, min_y, max_x, max_y |
| 363 | + if isinstance(img_intersection, Polygon): |
| 364 | + intersection_coords = np.array( |
| 365 | + [coord for coord in img_intersection.exterior.coords]) |
| 366 | + min_x = min(intersection_coords[:, 0]) |
| 367 | + min_y = min(intersection_coords[:, 1]) |
| 368 | + max_x = max(intersection_coords[:, 0]) |
| 369 | + max_y = max(intersection_coords[:, 1]) |
| 370 | + return min_x, min_y, max_x, max_y |
| 371 | + else: |
| 372 | + warnings.warn('img_intersection is not an object of Polygon.') |
| 373 | + return None |
370 | 374 | else:
|
371 | 375 | return None
|
372 | 376 |
|
|
0 commit comments