一、bin的读取与保存
import numpy as np
points = np.fromfile(file_path, dtype=np.float32).reshape(-1, 4)
保存
points.tofile('/media/wangchen/KINGSTON/数据集/pcd to bin/125.bin')
二、PCD的读取与保存
见这一篇文章如何读取或转换PCD点云文件_CVplayer111的博客-CSDN博客
三、TXT的读取与保存
def read_pcd(filepath):
lidar = []
with open(filepath, 'r', encoding='utf-8') 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)
line = f.readline().strip()
return np.array(lidar)
#方式二
with open(label_file, 'r') as f:
lines = f.readlines()
objects = [line.strip().split(' ') for line in lines]
return objects
import numpy as np
a = np.ones((2, 2))
##四个参数依次为文件名、数组、数据类型(浮点型)、分隔符(逗号)
np.savetxt("a.txt", a, fmt = '%f', delimiter = ',')
b = np.loadtxt('a.txt', delimiter = ',')