How can I output the open3d geometry PointCloud as .pcd file?

Question:

I am converting a lidar data (in .bin format) into .pcd format with the following code

with open ("lidar_velodyne64.bin", "rb") as f:
    byte = f.read(size_float*4)
    while byte:
        x,y,z,intensity = struct.unpack("ffff", byte)
        list_pcd.append([x, y, z])
        byte = f.read(size_float*4)
np_pcd = np.asarray(list_pcd)
pcd = o3d.geometry.PointCloud()
v3d = o3d.utility.Vector3dVector
pcd.points = v3d(np_pcd)

And trying to output ‘pcd’ as a .pcd file:

with open("pcd_output.pcd", "wb") as pcd2:
    pickle.dump(pcd,pcd2)

However, I got the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-cde8b419d929> in <module>
      1 with open("pcd_output.pcd", "wb") as pcd2:
----> 2     pickle.dump(pcd,pcd2)

TypeError: can't pickle open3d.open3d.geometry.PointCloud objects

How can I output the open3d geometry PointCloud as .pcd file?

Asked By: uguros

||

Answers:

Have you tried the default open3d.io.write_point_cloud() function?

According to the example here, you can use it as below:

import open3d as o3d
o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)
Answered By: ilke444