点云文件的格式转换:ply转pcd,pcd转pth,查看pth格式文件

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)

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值