如何将 .pcd 文件中的所有点导入到二维 python 数组中

问题描述 投票:0回答:3

如何从名为 edge_cloud.pcd 的文件中导入所有 3d 点并将它们放入数组中?我希望数组采用以下格式

array=[[xvalue1,yvalue1,zvalue1],[xvalue2,yvalue2,zvalue2]] 
python-3.x point-cloud-library
3个回答
10
投票

使用 Python 3.7.3、

numpy
1.16.2 和
open3d
0.7.0.0 进行测试:

import numpy as np 
import open3d as o3d

pcd = o3d.io.read_point_cloud("C:\\Users\\Username\\Source\\pointcloud\\bunny.pcd")
out_arr = np.asarray(pcd.points)  
print("output array from input list : ", out_arr)  

输出:

output array from input list :  
[[ 0.0054216  0.11349    0.040749 ]
 [-0.0017447  0.11425    0.041273 ]
 [-0.010661   0.11338    0.040916 ]
 ...
 [-0.064992   0.17802   -0.054645 ]
 [-0.069935   0.17983   -0.051988 ]
 [-0.07793    0.17516   -0.0444   ]]

输入PCD文件:

https://github.com/PointCloudLibrary/pcl/blob/master/test/bunny.pcd


1
投票

使用python 3.8进行测试,使用pypcd访问pcd文件。

使用以下命令安装

    pip install pypcd

如果未安装,请尝试以下命令

    python -m pip install --user git+https://github.com/DanielPollithy/pypcd.git

安装后,您可以使用以下代码将 pcd 加载到 numpy 数组。

    from pypcd import pypcd
    pc = pypcd.PointCloud.from_path("demo.pcd")
    pc_data = pc.pc_data
    pc_array = np.array([pc_data["x"], pc_data["y"], pc_data["z"]], dtype=np.float32)

https://github.com/dimatura/pypcd


0
投票

作为上面答案的补充,我发现

pypcd4
https://github.com/MapIV/pypcd4)通常在处理具有多种颜色的点云(如rgba)方面更加稳健和有能力和一个附加标签颜色标量字段)。

回答这个问题的

pypcd4
代码是

from pypcd4 import PointCloud

pc = PointCloud.from_path("Path")
data = pc.numpy(("x", "y", "z"))
© www.soinside.com 2019 - 2024. All rights reserved.