Foreword:
I learned the 3D OpenPCDet open source code before, and found out how to visualize the point cloud bin file of the Kitti dataset when I need to make my own dataset. Here is an update note work
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~~~~~~~~~~~~~~")
The mian function is set to read all the bin files in the folder in a loop, and only read one corresponding modification.