pcd2binary.py 831 B

1234567891011121314151617181920212223
  1. import open3d as o3d
  2. import numpy as np
  3. def pcd_to_binary(pcd_file, output_file):
  4. pcd = o3d.io.read_point_cloud(pcd_file)
  5. points = np.asarray(pcd.points)
  6. binary_data = points[:, :3]
  7. with open(output_file, 'wb') as f:
  8. f.write(binary_data.tobytes())
  9. # def binary_to_nparray(binary_file, output_file):
  10. # with open(binary_file, 'rb') as f:
  11. # binary_data = f.read()
  12. # # 将二进制数据转换为 NumPy 数组
  13. # point_cloud = np.frombuffer(binary_data, dtype=np.float64).reshape(-1, 3)
  14. # np.savetxt(output_file, point_cloud)
  15. if __name__ == '__main__':
  16. pcd_to_binary(r'/home/robot/ROS/ren_yuan/ren_yuan_pointcloud/123.pcd', r'/home/robot/ROS/ren_yuan/ren_yuan_pointcloud/pointcloud.txt')
  17. #binary_to_nparray(r'./pointcloud.txt', r'./111123123123.txt')