obj_names = annotations['name']
num_objects = obj_names.shape[0]
points = self.get_lidar(info)
corners_lidar = box_utils.boxes_to_corners_3d(annotations['gt_boxes_lidar'])
for k in range(num_objects):
flag = box_utils.in_hull(points[:, 0:3], corners_lidar[k]) # 在box内的点云数量
num_points_in_gt[k] = flag.sum()
from scipy.spatial import Delaunay
def in_hull(p, hull):
"""
:param p: (N, K) test points
:param hull: (M, K) M corners of a box
:return (N) bool
"""
try:
if not isinstance(hull, Delaunay):
hull = Delaunay(hull)
flag = hull.find_simplex(p) >= 0
except scipy.spatial.qhull.QhullError:
print('Warning: not a hull %s' % str(hull))
flag = np.zeros(p.shape[0], dtype=np.bool)
return flag
def boxes_to_corners_3d(boxes3d):
"""
7 -------- 4
/| /|
6 -------- 5 .
| | | |
. 3 -------- 0
|/ |/
2 -------- 1
Args:
boxes3d: (N, 7) [x, y, z, dx, dy, dz, heading], (x, y, z) is the box center
Returns:
"""
boxes3d, is_numpy = common_utils.check_numpy_to_torch(boxes3d) # [71, 7]
template = boxes3d.new_tensor(( # [8, 3]
[1, 1, -1], [1, -1, -1], [-1, -1, -1], [-1, 1, -1],
[1, 1, 1], [1, -1, 1], [-1, -1, 1], [-1, 1, 1],
)) / 2
corners3d = boxes3d[:, None, 3:6].repeat(1, 8, 1) * template[None, :, :] # [71, 8, 3]
corners3d = common_utils.rotate_points_along_z(corners3d.view(-1, 8, 3), boxes3d[:, 6]).view(-1, 8, 3) # [71, 8, 3]
corners3d += boxes3d[:, None, 0:3]
return corners3d.numpy() if is_numpy else corners3d
计算在box内点云的数量
最新推荐文章于 2025-03-19 11:43:37 发布