前言
KITTI数据集是自动驾驶和计算机视觉领域中一个广泛使用的基准数据集,它提供了丰富的传感器数据,包括激光雷达、相机和GPS等。Open3D是一个功能强大的3D数据处理和可视化库,支持多种3D数据格式。本文将介绍如何使用Open3D对KITTI数据集的检测结果进行可视化。
准备工作
确保你已经安装了Open3D库。如果尚未安装,可以通过pip安装:
pip install open3d
加载点云
points = np.fromfile(str(bin_file), dtype=np.float32).reshape(-1, 4)mask = points[:,0]>0points= points[mask]pts = o3d.geometry.PointCloud() pts.points = o3d.utility.Vector3dVector(points[:, :3])
解析检测框
def get_obj_corners(obj):center = [obj["Center"]["CenterX"], obj["Center"]["CenterY"], obj["Center"]["CenterZ"]]size = [obj["Size"]["ObjectLength"], obj["Size"]["ObjectWidth"], obj["Size"]["ObjectHeight"]]yaw = obj["Yaw"]rot = np.asmatrix([[math.cos(yaw), -math.sin(yaw)],\[math.sin(yaw), math.cos(yaw)]])plain_pts = np.asmatrix([[0.5 * size[0], 0.5*size[1]],\[0.5 * size[0], -0.5*size[1]],\[-0.5 * size[0], -0.5*size[1]],\[-0.5 * size[0], 0.5*size[1]]])tran_pts = np.asarray(rot * plain_pts.transpose())tran_pts = tran_pts.transpose()corners = np.arange(24).astype(np.float32).reshape(8, 3)for i in range(8):corners[i][0] = center[0] + tran_pts[i%4][0]corners[i][1] = center[1] + tran_pts[i%4][1]corners[i][2] = center[2] + (float(i >= 4) - 0.5) * size[2]return cornersdef render_3dbbox(points, color):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 = [color for i in range(len(lines))]line_set = o3d.geometry.LineSet()line_set.points = o3d.utility.Vector3dVector(points)line_set.lines = o3d.utility.Vector2iVector(lines)line_set.colors = o3d.utility.Vector3dVector(colors)return line_set
结果可视化
源码下载
添加我的微信ailaukalfp29, 回复Open3d