Skip to content

How to convert the `open3d.geometry.VoxelGrid` into a `NumPy` array

AlexZakIntel edited this page Jan 27, 2022 · 3 revisions

Q: How to convert the open3d.geometry.VoxelGrid into a NumPy array?

A:

You can get the voxel indices and colors as Numpy arrays like this:

voxels = voxel_grid.get_voxels()  # returns list of voxels
indices = np.stack(list(vx.grid_index for vx in voxels))
colors = np.stack(list(vx.color for vx in voxels))

To get the color of a point given its coordinates, use this function:

http://www.open3d.org/docs/latest/python_api/open3d.geometry.VoxelGrid.html#open3d.geometry.VoxelGrid.get_voxel

The returned voxel has grid_index and color fields. If you directly have the voxel index, you will need to convert it to the coordinates of the center of the voxel first.

For more detailed information, please see our Issues page at: https://github.com/isl-org/Open3D/issues/1418#issuecomment-1003460629