Python3下用mayavi将KITTI点云数据可视化

前言:

前面学习3D的OpenPCDet开源代码,发现需要自己制作数据集的时候,如何将Kitti数据集的点云bin文件进行可视化,这里进行一个更新备注的工作

import mayavi.mlab
import torch
import numpy as np
import os


def viz_mayavi(points, vals="distance"):  # 可视化只用到了3维数据(x,y,z)!
    x=points[:, 0]
    y=points[:, 1]
    z=points[:, 2]
    d=torch.sqrt(x**2+y**2)

    if vals == "height":
        col = z
    else:
        col = d
    # 创建可视化模板的尺寸
    fig=mayavi.mlab.figure(bgcolor=(0, 0, 0), size=(1280, 720))
    mayavi.mlab.points3d(x, y, z,
                         col,
                         mode="point",
                         colormap='spectral',
                         figure=fig,
                         )

    mayavi.mlab.show()


if __name__ == "__main__":
    bin_file_path = '***\\1_txt2pcd'
    bin_files = os.listdir(bin_file_path)
    for bin_file in bin_files:
        if bin_file.endswith(".bin"):
            mypointcloud = np.fromfile(bin_file_path + '/' + bin_file, dtype=np.float32, count=-1).reshape([-1, 3])
            mypointcloud = torch.from_numpy(mypointcloud)
            print(mypointcloud.size())
            print(mypointcloud.type())
            viz_mayavi(mypointcloud, vals="height")
            print("~~~~~~~~~~~~~~I am a Seg. line~~~~~~~~~~~~~~")

mian函数里面设置了循环读取文件夹下所有bin文件,只读一个对应修改即可

你可能感兴趣的:(学习,python,自动驾驶)