当前位置:   article > 正文

open3d,python-pcl,numpy 点云数据格式转换_python 'pcl

python 'pcl

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函数,具体操作如下:

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

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)        
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

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]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/894295
推荐阅读
相关标签
  

闽ICP备14008679号