目录
bin格式可视化
1.安装依赖库
2. bin格式文件进行可视化
open3d可视化:
npy可视化
matplotlib可视化
pip install mayavi -i https://pypi.tuna.tsinghua.edu.cn/simple
import mayavi.mlab
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]
r=points[:, 3] # reflectance value of point
d=np.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 = 'bin_2pcd'
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, 4])
viz_mayavi(mypointcloud,vals="height"
【Open3D】点云可视化 - 知乎
成功可视化bin文件
import math
import numpy as np
import struct
import os
import open3d as o3d
def read_velodyne_bin(path):
pc_list = []
with open(path, 'rb') as f:
content = f.read()
pc_iter = struct.iter_unpack('ffff', content)
for idx, point in enumerate(pc_iter):
pc_list.append([point[0], point[1], point[2]])
return np.asarray(pc_list, dtype=np.float32)
def show_point(data):
pcd = o3d.geometry.PointCloud()
# pcd.points = o3d.utility.Vector3dVector(origin)
# o3d.visualization.draw_geometries([pcd])
pcd.points = o3d.utility.Vector3dVector(data)
o3d.visualization.draw_geometries([pcd])
def main():
root_dir = r'\\tsclient\velodyne' # 激光雷达bin文件路径
cat = os.listdir(root_dir)
iteration_num = len(cat)
for i in range(iteration_num):
filename = os.path.join(root_dir, cat[i])
db_np = read_velodyne_bin(filename)
show_point(db_np)
if __name__ == '__main__':
main()
参考:Open3d显示点云数据_open3d 加载bin代码-CSDN博客
import numpy as np
import matplotlib.pyplot as plt
depthmap = np.load('0000.npy') #使用numpy载入npy文件
plt.imshow(depthmap) #执行这一行后并不会立即看到图像,这一行更像是将depthmap载入到plt里
plt.savefig('depthmap.jpg') #执行后可以将文件保存为jpg格式图像,可以双击直接查看。也可以不执行这一行,直接执行下一行命令进行可视化。但是如果要使用命令行将其保存,则需要将这行代码置于下一行代码之前,不然保存的图像是空白的
plt.show() #在线显示图像