Skip to content

Commit 03d0164

Browse files
authored
[Fix] Fix AttributeError: 'LineString' object has no attribute 'exterior' (#2557)
* Fix bug: AttributeError: 'LineString' object has no attribute 'exterior' * fixed linter * fixed linter * fix linter issue wit isort
1 parent b5a706d commit 03d0164

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

mmdet3d/datasets/convert_utils.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
22
import copy
3+
import warnings
34
from typing import List, Optional, Tuple, Union
45

56
import numpy as np
67
from nuscenes import NuScenes
78
from nuscenes.utils.geometry_utils import view_points
89
from pyquaternion import Quaternion
910
from shapely.geometry import MultiPoint, box
11+
from shapely.geometry.polygon import Polygon
1012

1113
from mmdet3d.structures import Box3DMode, CameraInstance3DBoxes, points_cam2img
1214
from mmdet3d.structures.ops import box_np_ops
@@ -358,15 +360,17 @@ def post_process_coords(
358360

359361
if polygon_from_2d_box.intersects(img_canvas):
360362
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
370374
else:
371375
return None
372376

0 commit comments

Comments
 (0)