Python将xyz数组转换为PLY文件

用np生成点云数据 

import open3d as o3d;
import numpy as np;

# Generate some neat n times 3 matrix using a variant of sync function
x = np.linspace(-3, 3, 501)
mesh_x, mesh_y = np.meshgrid(x, x)
z = np.sinc((np.power(mesh_x, 2) + np.power(mesh_y, 2)))
z_norm = (z - z.min()) / (z.max() - z.min())
xyz = np.zeros((np.size(mesh_x), 3))
xyz[:, 0] = np.reshape(mesh_x, -1)
xyz[:, 1] = np.reshape(mesh_y, -1)
xyz[:, 2] = np.reshape(z_norm, -1)
print('xyz')
print(xyz)


# Pass xyz to Open3D.o3d.geometry.PointCloud and visualize
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz)
o3d.io.write_point_cloud("sync.ply", pcd) 

pcdsync = o3d.io.read_point_cloud("sync.ply")

# print(pcdsync)
# print(np.asarray(pcdsync.points))
o3d.visualization.draw_geometries([pcdsync],
                                  zoom=0.3412,
                                  front=[0.4257, -0.2125, -0.8795],
                                  lookat=[2.6172, 2.0475, 1.532],
                                  up=[-0.0694, -0.9768, 0.2024])

 随机生成点云数据

#随机生成500个点云数据
number_points =500
xyz1=np.random.rand(number_points,3)
print('xyz1')
print(xyz1)

#用户指定的点云数据
xyz2=np.array([[0.41267751, 0.06395023,1.93730013],
 [0.94504276, 0.19493055 ,0.91263999],
 [0.4647774 , 0.29706205 ,0.0173361 ],
 [0.87313897 ,0.81752111 ,0.5364261 ],
 [0.25777678 ,0.31743575 ,0.34583599]])

# Pass xyz to Open3D.o3d.geometry.PointCloud and visualize
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz1) #这里设置需要显示的点云
o3d.io.write_point_cloud("sync.ply", pcd) 

pcdsync = o3d.io.read_point_cloud("sync.ply")

o3d.visualization.draw_geometries([pcdsync])

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值