行走的蓑衣客

导航

< 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
统计
 
复制代码
#open3d安装:pip3 install open3d-python
import open3d as o3d
import numpy as np

def makePlyFile(xyzs, labels, fileName='makeply.ply'):
    '''Make a ply file for open3d.visualization.draw_geometries
    :param xyzs:    numpy array of point clouds 3D coordinate, shape (numpoints, 3).
    :param labels:  numpy array of point label, shape (numpoints, ).
    '''
    RGBS = [
        (0, 255, 255),
        (255, 0, 0),
        (0, 255, 0),
        (0, 0, 255),
        (0, 0, 0),
        (255, 0, 255)
    ]

    with open(fileName, 'w') as f:
        f.write('ply\n')
        f.write('format ascii 1.0\n')
        f.write('comment PCL generated\n')
        f.write('element vertex {}\n'.format(len(xyzs)))
        f.write('property float x\n')
        f.write('property float y\n')
        f.write('property float z\n')
        f.write('property uchar red\n')
        f.write('property uchar green\n')
        f.write('property uchar blue\n')
        f.write('end_header\n')
        for i in range(len(xyzs)):
            r, g, b = (255, 0, 0)

            x, y, z = xyzs[i]
            f.write('{} {} {} {} {} {}\n'.format(x, y, z, r, g, b))

if __name__ == "__main__":
    xyzs=[]
    with open("point.txt", "r") as f:
        for line in f.readlines():
            p=[]
            line = line.strip('\n')  # 去掉列表中每一个元素的换行符
            a=line.split(",")
            p.append(float(a[0]))
            p.append(float(a[1]))
            p.append(float(a[2]))
            xyzs.append(p)

    numpoints=len(xyzs)
    labels = np.random.randint(0, 4, numpoints)  # 4种label
    makePlyFile(xyzs, labels, 'demo.ply')
    pcd = o3d.io.read_point_cloud('demo.ply')
    o3d.visualization.draw_geometries([pcd])
复制代码

 


 

posted on   行走的蓑衣客  阅读(677)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
 
点击右上角即可分享
微信分享提示