open3d,python-pcl,numpy 点云数据格式转换
NumPy 转 open3d.PointCloud
参考: 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函数,具体操作如下:文章来源地址https://www.toymoban.com/news/detail-692056.html
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)
open3d.PointCloud 转 NumPy
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])
numpy 数组保存为 pcd 文件
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)
python pcl 点云转 numpy
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]
numpy 转 python pcl点云
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
文章来源:https://www.toymoban.com/news/detail-692056.html
到了这里,关于open3d,python-pcl,numpy 点云数据格式转换的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!