赞
踩
参考: https://www.codenong.com/cs106756630/
numpy转open3D需要借助Vector3dVector函数,这样可以直接赋值与open3d.PointCloud.points,具体操作如下,假设(x, y, z)、(n_x, n_y, n_z)、(r, g, b)分别是一个n*3numpy数组(这三者不一定全部需要),则对于点数,法向量和颜色的转换都可以借助Vector3dVector函数,具体操作如下:
import numpy as np
import open3D as o3d
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz)
pcd.normals = o3d.utility.Vector3dVector(nxnynz)
pcd.colors = o3d.utility.Vector3dVector(rgb)
import numpy as np
import open3d as o3d
# Load saved point cloud and visualize it
pcd_load = o3d.io.read_point_cloud("../xxx.ply")#或 xxx.pcd 等常见格式
# convert Open3D.o3d.geometry.PointCloud to numpy array
xyz_load = np.asarray(pcd_load.points)
o3d.visualization.draw_geometries([pcd_load])
import numpy as np
import open3d as o3d
# pointcloud_interest 为 numpy数组
# pointcloud_interest =rays_end_all.numpy()
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(pointcloud_interest)
# print("len(pcd.points):",len(pcd.points))#add hxz
o3d.io.write_point_cloud("/home/xx/pointcloud_interest.pcd", pcd)
import pcl
import numpy as np
# 读取pcl 格式点云 并转换为 numpy数组
pointcloud_source = pcl.load('xx.pcd')
pointcloud_source_numpy = pointcloud_source.to_array()
# pointcloud_source_numpy = pointcloud_source.to_array()[:, :4]
import pcl
import numpy as np
# 转换为 pcl 格式点云,输入点云 points_,形状(N,3)
if(0): # 将 double 转换为 float32_t, 可能需要
points=np.ones((points_.shape[0],3),np.float32)
for i in range(points_.shape[0]):
points[i][0]=points_[i][0]
points[i][1]=points_[i][1]
points[i][2]=points_[i][2]
pointcloud_trans = pcl.PointCloud(points)# numpy 数组转 pcl
if(1):
pointcloud_trans = pcl.PointCloud(points_)# numpy 数组转 pcl
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。