7

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]] 
Brian Kreidberg
  • 179
  • 1
  • 13

2 Answers2

9

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

phoenix
  • 7,988
  • 6
  • 39
  • 45
iokevins
  • 1,427
  • 2
  • 19
  • 29
  • What if my points have 5 dimensions, like [x, y, z, intensity, time_stamp], open3d only provides format with 3,4,6 dimensions... – zheyuanWang Oct 27 '22 at 13:39
  • >>> import open3d as o3d Traceback (most recent call last): File "", line 1, in File "/home/jhuai/.local/lib/python3.8/site-packages/open3d/__init__.py", line 9, in from open3d.linux import * File "/home/jhuai/.local/lib/python3.8/site-packages/open3d/linux/__init__.py", line 7, in globals().update(importlib.import_module('open3d.linux.open3d').__dict__) File "/usr/lib/python3.8/importlib/__init__.py", line 127 ImportError: /home/jhuai/.local/lib/python3.8/site-packages/open3d/linux/open3d.so: undefined symbol: _Py_ZeroStruct – jhuai Jul 03 '23 at 13:26
1

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)

https://github.com/dimatura/pypcd

  • >>> from pypcd import pypcd Traceback (most recent call last): File "", line 1, in File "/home/jhuai/.local/lib/python3.8/site-packages/pypcd/pypcd.py", line 15, in import cStringIO as sio ModuleNotFoundError: No module named 'cStringIO' – jhuai Jul 03 '23 at 13:22