Conversion between pointcloud and numpy arrays in open3d

In open3d, after using open3d.io.read_point_cloud() to read the point cloud data, the returned data is pointcloud type. Sometimes it is hoped that numpy can be used to process the point cloud. At this time, it is necessary to convert between the two (strictly speaking It's just that the data is copied and retransmitted).
1. Convert pointcloud to numpy

import numpy as np
import open3d as o3d
A=[]
pcd=o3d.io.read_point_cloud("/bunny.ply")#路径需要根据实际情况设置
A=np.asarray(pcd.points)#A已经变成n*3的矩阵
print(A)

2. The data in the numpy array is converted into pointcloud

#这里B已经是一个n*3的numpy.ndarray(也就是常见的数组类型)
pcd=o3d.geometry.PointCloud()#实例化一个pointcloud类
pcd.points=o3d.utility.Vector3dVector(B)#给该类传入坐标数据,此时pcd.points已经是一个点云了
o3d.visualization.draw_geometries([pcd])#显示一下

Reference 1
Reference 2

Guess you like

Origin blog.csdn.net/ZauberC/article/details/129885903