用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])