# 绘制矩形框 def draw_bounding_box(pcd, label): corners = get_box_corners(label) lines = [[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4], [1, 5], [2, 6], [3, 7]] colors = [[0, 0, 0] for i in range(len(lines))] line_set = o3d.geometry.LineSet(points=o3d.utility.Vector3dVector(corners), lines=o3d.utility.Vector2iVector(lines)) line_set.colors = o3d.utility.Vector3dVector(colors) pcd += line_set return pcd # 获取矩形框的8个顶点坐标 def get_box_corners(label): h, w, l = label['dimensions'] x, y, z = label['location'] ry = label['rotation_y'] # 3D bounding box corners corners = np.array([ [-l / 2, -h, -w / 2], [l / 2, -h, -w / 2], [l / 2, -h, w / 2], [-l / 2, -h, w / 2], [-l / 2, 0, -w / 2], [l / 2, 0, -w / 2], [l / 2, 0, w / 2], [-l / 2, 0, w / 2] ]) # rotation rot_mat = np.array([ [np.cos(ry), 0, np.sin(ry)], [0, 1, 0], [-np.sin(ry), 0, np.cos(ry)] ]) corners = corners @ rot_mat.T # translation corners += np.array([x, y, z]) return corners
时间: 2023-06-25 08:06:59 浏览: 101
to_draw_bounding-box.zip_boundingbox_box
这是一个用于绘制点云数据中物体矩形框的函数。它的输入是点云数据和一个包含物体位置、尺寸和旋转信息的标签。首先,通过调用 `get_box_corners` 函数获取矩形框的8个顶点坐标。接下来,将这些点与每条边的索引组成线段列表,并将其作为 `LineSet` 对象添加到点云中。最后,将 `LineSet` 对象的颜色设置为黑色,并返回更新后的点云数据。
阅读全文