随笔 - 1762  文章 - 0  评论 - 109  阅读 - 431万

把 .xyz 文件转换成 .ply 文件

把 .xyz 文件转换成 .ply 文件 (加头文件)_python将.ply转为.xyz-CSDN博客

复制代码
from plyfile import PlyData,PlyElement
import re
import numpy as np
from os.path import join

def write_ply(save_path,points,text=True):
    
    points = [(points[i,0], points[i,1], points[i,2]) for i in range(points.shape[0])]
    vertex = np.array(points, dtype=[('x', 'f4'), ('y', 'f4'),('z', 'f4')])
    el = PlyElement.describe(vertex, 'vertex', comments=['vertices'])
    PlyData([el], text=text).write(save_path)


A = []
timestamps = []

with open('/Users/manmi/Documents/data/square_data/mm_data/timestamp.txt') as f:
    content = f.readlines()
    for line in content:
        timestamp = int(line)
        timestamps.append(timestamp)
timestamps.sort()      


for k in range(0, len(timestamps)):
    src_tamestamp = timestamps[k]
    path = join('/Users/manmi/Documents/data/square_data/mm_data/mm_xyz', str(src_tamestamp)+'.xyz')              
    with open(path) as f:
        content = f.readlines()
        for line in content:
            x = float(re.split('\s+', line)[0])
            y = float(re.split('\s+', line)[1])
            z = float(re.split('\s+', line)[2])
            A.append((x,y,z))
    points = np.array(A)

    savepath = join('/Users/manmi/Documents/data/square_data/mm_data/mm_ply',str(src_tamestamp)+'.ply')
    write_ply(savepath, points, text=True)
复制代码

 

posted on   一杯明月  阅读(120)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
历史上的今天:
2021-06-15 显示器把伽马值调高的方法
2020-06-15 吉他教学第一节
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示