nuScenes数据集使用方法(1)可视化初探

2023-12-20 23:20:20
import os
import matplotlib.pyplot as plt
from nuscenes.nuscenes import NuScenes
from nuscenes.utils.data_classes import LidarPointCloud
import open3d as o3d


nusc = NuScenes(version='v1.0-mini', dataroot='/home/xxxx/Downloads/nuScene_data', verbose=True)
my_scene = nusc.scene[0]

first_sample_token = my_scene['first_sample_token']
sample = nusc.get('sample', first_sample_token)

my_annotation_token = sample['anns'][18]
my_annotation_metadata = nusc.get('sample_annotation', my_annotation_token)
nusc.render_annotation(my_annotation_token)

plt.show()


top_lidar_token = sample['data']['LIDAR_TOP']
top_lidar_data = nusc.get('sample_data', top_lidar_token)

pcd_bin_file = os.path.join(nusc.dataroot, top_lidar_data['filename'])

# Load the .pcd.bin file.
pc = LidarPointCloud.from_file(pcd_bin_file)
pcd = pc.points.T
pcd = pcd.reshape((-1, 4))[:, 0:3]

point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(pcd)

# 可视化点云
o3d.visualization.draw_geometries([point_cloud])

print("done")

在官网下载并解压缩

?首先获取一个场景

nusc = NuScenes(version='v1.0-mini', dataroot='/home/xxxx/Downloads/nuScene_data', verbose=True)
my_scene = nusc.scene[0]

从场景中获取第一个样本,也就是一帧

first_sample_token = my_scene['first_sample_token']
sample = nusc.get('sample', first_sample_token)

如果想找下一个样本,每一个样本中储存着下一个样本的token,一个一个往下找

获取标注

my_annotation_token = sample['anns'][18]
my_annotation_metadata = nusc.get('sample_annotation', my_annotation_token)
nusc.render_annotation(my_annotation_token)

plt.show()

18表示的是,这个样本中被标注的第18个物体

可视化雷达点云

top_lidar_token = sample['data']['LIDAR_TOP']
top_lidar_data = nusc.get('sample_data', top_lidar_token)

pcd_bin_file = os.path.join(nusc.dataroot, top_lidar_data['filename'])

# Load the .pcd.bin file.
pc = LidarPointCloud.from_file(pcd_bin_file)
pcd = pc.points.T
pcd = pcd.reshape((-1, 4))[:, 0:3]

point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(pcd)

# 可视化点云
o3d.visualization.draw_geometries([point_cloud])

文章来源:https://blog.csdn.net/qq_41816368/article/details/135116727
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。