How do you import all the 3d points from a file named edge_cloud.pcd and put them into an array? I want the array to be in the format
array=[[xvalue1,yvalue1,zvalue1],[xvalue2,yvalue2,zvalue2]]
How do you import all the 3d points from a file named edge_cloud.pcd and put them into an array? I want the array to be in the format
array=[[xvalue1,yvalue1,zvalue1],[xvalue2,yvalue2,zvalue2]]
Tested with Python 3.7.3, numpy
1.16.2, and 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:
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 ]]
Input PCD file:
https://github.com/PointCloudLibrary/pcl/blob/master/test/bunny.pcd
Tested with python 3.8, access pcd files using pypcd.
Install using below command
pip install pypcd
If this doesnt install, try below command
python -m pip install --user git+https://github.com/DanielPollithy/pypcd.git
After the installation you can load pcd to numpy arrays using below code.
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)
As an addition to the answer above I found pypcd4
(https://github.com/MapIV/pypcd4) to be generally a lot more robust and capable in terms of dealing with point clouds with multiple colorings (like rgba and an additional label color scalar feild).
The pypcd4
code that answers this question would be
from pypcd4 import PointCloud
pc = PointCloud.from_path("Path")
data = pc.numpy(("x", "y", "z"))
© 2022 - 2024 — McMap. All rights reserved.