nuscenes激光雷达数据抽稀

nuScenes文件说明

Mini nuScenes下载后得到名称为“v1.0-mini.tgz”的压缩包,主要包含maps、samples、sweeps和v1.0-mini等4个文件夹。下面分别进行简要介绍。

maps:数据采集的地图路线,是一个二值图,道路所在路线对应的像素值为255,其它像素值为0。
samples:数据样本,分别包括6 个摄像头、1 个激光雷达、5 个毫米波雷达所采集的数据,每个传感器采集404个样本。数据来源于10个场景,且每个场景共采集了约连续20秒数据。samples中的数据是在这些连续数据样本中,以2Hz频率进行采样,即每秒2张图片。摄像头采集数据集保存为jpg图像格式,激光雷达和毫米波雷达采集数据保存为pcd点云格式。各个传感器的数据文件总数为12x404=4848。其中,激光雷达的点云属性包括空间坐标x、y、z、反射强度和雷达垂直方向扫描序号(32线雷达的取值范围为0~31)。
sweeps:samples中的数据是经过2Hz采样得到的数据。sweeps中存储的则是连续扫描得到约20秒传感器数据,存储结构和格式完全与samples文件夹一致。由于数据是连续扫描得到的,其可以用来合成视频,模拟实际连续检测的效果。各个传感器的数据文件总数为26358。
V1.0-mini:该文件夹中主要包含了数据详细说明,例如传感器标定参数、目标类别、标注信息等,共包含13个json文件下面将分别进行详细介绍。

背景介绍

nuscenes激光雷达数据是32线的,而公司激光雷达是16线的,为了数据的统一,将nuscenes激光雷达数据32线抽稀成16线,重新做训练,具体的抽稀代码如下:

#! /usr/bin/env python
# -*- coding: utf-8 -*-#
# -------------------------------------------------------------------------------
# Name:         Open3dShowPcd
# Author:       yunhgu
# Date:         2021/12/22 9:07
# Description: 
# -------------------------------------------------------------------------------
from pathlib import Path

import numpy as np
import open3d as o3d
from traceback import format_exc

def read_pcd(filepath):
    lidar = []
    lidars = []
    with open(filepath,'r') as f:
        line = f.readline().strip()
        while line:
            linestr = line.split(" ")
            if len(linestr) == 4:
                linestr_convert = list(map(float, linestr))
                lidar.append(linestr_convert)
                lidars.extend(linestr_convert)
            line = f.readline().strip()
    return np.array(lidar, dtype=np.float32)

class PtVis:
    def __init__(self, name='空格进入下一帧 Z退回上一帧', width=1024, height=768, pcd_files_path=""):
        self.pcd_files_path = pcd_files_path
        self.pcd_files_list = []
        self.index = 0
        self.pcd = None
        self.vis = None
        self.name = name
        self.width = width
        self.height = height
        self.axis_pcd = o3d.geometry.TriangleMesh().create_coordinate_frame()
        self.init_pcd_files_list()

    def init_setting(self):
        opt = self.vis.get_render_option()
        # 设置背景颜色和点大小
        opt.background_color = np.asarray([0, 0, 0])
        opt.point_size = 2

    def show_pcd(self):
        # 绘制open3d坐标系
        # read_pcd(self.pcd_files_list[0])
        for index in range(len(self.pcd_files_list)):
            points = np.fromfile(self.pcd_files_list[index], dtype=np.float32).reshape(-1, 5)
            shape = list(points.shape)
            print(list(points.shape))
            delete_index = []
            for a in range(shape[0]):
                if points[a][4]%2 == 0:
                    delete_index.append(a)
                #print(np.arctan(points[a][2] / (np.sqrt(np.square(points[a][0]) + np.square(points[a][1])))))
                #sfor b in range(shape[1]):
            points = np.delete(points, delete_index, axis=0)
            points.tofile(self.pcd_files_list[index])
            print(list(points.shape))
            print(len(self.pcd_files_list),"*********",index)
        
        #np.delete(arr, 1, axis=0)

        # self.vis = o3d.visualization.VisualizerWithKeyCallback()
        # self.vis.create_window(window_name=f"{Path(self.pcd_files_list[0]).name} {self.name}", width=self.width,
        #                        height=self.height)
        # # 修改显示
        # self.init_setting()
        # # self.pcd = o3d.geometry.uniform_down_sample(self.pcd_files_list[0],2)
        # # 初始化显示pcd第一帧
        # self.pcd = o3d.io.read_point_cloud(self.pcd_files_list[0])
        # # 每5个点取一个,最后点数量变为原始数量的 1/5
        # self.pcd = self.pcd.uniform_down_sample(2)
        # # self.pcd = self.pcd.voxel_down_sample(voxel_size=0.5)
        # # 写pcd点云文件
        # # 保存点云文件的函数为o3d.io.write_point_cloud。
        # # o3d.io.write_point_cloud(path, pcd)
        # # 注意事项:这样保存的文件可以被open3d直接读取,但是用其他方式读取时可能会出现如下所示的编码错误,因此最好指定保存的编码方式。
        # o3d.io.write_point_cloud("./sparse_result.pcd", self.pcd , write_ascii=True)

        # self.vis.add_geometry(self.pcd)
        # self.vis.add_geometry(self.axis_pcd)
        # # 设置键盘响应事件
        # self.vis.register_key_callback(90, lambda temp: self.last())
        # self.vis.register_key_callback(32, lambda temp: self.next())
        # self.vis.run()

    def next(self):
        if 0 <= self.index < len(self.pcd_files_list) - 1:
            self.index += 1
        self.update(self.index)

    def last(self):
        if 0 < self.index <= len(self.pcd_files_list) - 1:
            self.index -= 1
        self.update(self.index)

    def init_pcd_files_list(self):
        for file in Path(self.pcd_files_path).rglob("*.bin"):
            self.pcd_files_list.append(str(file))
        self.pcd_files_list = sorted(self.pcd_files_list, key=lambda p: Path(p).stem)

    def update(self, index):
        new_pcd_file = self.pcd_files_list[index]
        self.vis.create_window(window_name=f"{Path(new_pcd_file).name} {self.name}", width=self.width,
                               height=self.height)
        self.pcd = o3d.io.read_point_cloud(new_pcd_file)
        self.vis.clear_geometries()  # 清空vis点云
        self.vis.add_geometry(self.pcd)  # 增加vis中的点云
        self.vis.add_geometry(self.axis_pcd)
        self.vis.poll_events()
        self.vis.update_renderer()

    def close(self):
        self.vis.destroy_window()


if __name__ == '__main__':
    pt = None
    try:
        #pcd_file_path = input("请输入要展示的pcd文件夹:").strip("\"")
        #pcd_file_path = "/media/data/zs/project/天准车机/caiji/pcd_png_save/pcd/2023-03-21-18-34-01"
        pcd_file_path = "/media/data/zs/project/detection3D/github/CenterPoint-master_zs/data/nuScenes/v1.0-test/sweeps/LIDAR_TOP"
        # pcd_file_path = r"C:\Users\pc\Desktop\docker\output\result"
        pt = PtVis(pcd_files_path=pcd_file_path)
        print(f"{pcd_file_path}共有PCD个数:{len(pt.pcd_files_list)}")
        pt.show_pcd()
    except Exception as e:
        print(f"运行出错请联系开发人员:{format_exc}{e}")
    finally:
        pt.close()
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值