1.ply格式转pcd格式:
import open3d as o3d
def convert_ply_to_pcd(ply_file, pcd_file):
# 读取PLY文件
point_cloud = o3d.io.read_point_cloud(ply_file)
# 保存为PCD文件
o3d.io.write_point_cloud(pcd_file, point_cloud)
# 使用示例
ply_file_path = 'test.ply' #填入ply文件的路径
pcd_file_path = 'test.pcd' #填入pcd文件的路径
convert_ply_to_pcd(ply_file_path, pcd_file_path)
2.pcd转pth格式:
import numpy as np
import torch
import numpy as np
import pcl
def pcd_to_pth(pcd_file, pth_file):
cloud = pcl.load(pcd_file)
points = np.asarray(cloud)
tensor = torch.from_numpy(points)
tensor = tensor.float() # 将张量转换为浮点类型
tensor = tensor.numpy() # 将张量转换回NumPy数组
tensor = tensor.astype(np.float32) # 将数据类型转换为np.float32
torch.save(tensor, pth_file)
# 示例用法
pcd_file = 'test.pcd' #文件路径
pth_file = 'test.pth' #文件路径
pcd_to_pth(pcd_file, pth_file)
3.查看pth文件:
import torch
def view_pth(pth_file):
tensor = torch.load(pth_file)
print("Tensor shape:", tensor.shape)
print("Example data:")
print(tensor[:100]) # 打印前10个数据作为示例
# 示例用法
pth_file = 'test.pth' #文件路径
view_pth(pth_file)