本文所用数据示例参考👉详见👈
1.读取点云二进制数据
输入:bin点云数据
输出:txt文本文件
from tkinter import filedialog
import struct
def open_file():
file_path = filedialog.askopenfilename(title='Select file')
return file_path
file_path = open_file()
output_path = "D:\Data\output.txt"
pc_list = []
with open(file_path, 'rb') as bin_file:
data = bin_file.read()
pc_float = struct.iter_unpack('fffff', data) # 把bytes变成相应的python数据类型
for point in pc_float:
pc_list.append(point)
with open(output_path, 'w') as txt_file:
for point in pc_list:
txt_file.write(str(point).replace('(', '').replace(')', '') + '\n')
2.显示点云二进制数据
输入:bin点云数据
输出:点云图片
from tkinter import filedialog
import numpy as np
import mayavi.mlab
def open_file():
file_path = filedialog.askopenfilename(title='Select file')
return file_path
# load .bin file
lidar_path = open_file()
pointcloud = np.fromfile(lidar_path, dtype=np.float32, count=-1).reshape([-1,5])
x = pointcloud[:, 0] # x position of point
y = pointcloud[:, 1] # y position of point
z = pointcloud[:, 2] # z position of point
r = pointcloud[:, 3] # reflectance value of point
d = np.sqrt(x