Open3D Working with Numpy

简介: Open3D Working with Numpy

Working with Numpy

Open3D中的所有数据结构都与NumPy缓冲区本身兼容。以下教程使用NumPy生成同步函数的变体,并使用Open3D可视化该函数。

首先,我们生成一个n×3矩阵xyz 。 每列都有xyz 函数z=sin(x^2+y^2)/(x^2+y^2[0,1] 范围的归一化映射。

# Generate some neat n times 3 matrix using a variant of sync function
x = np.linspace(-3, 3, 401)
mesh_x, mesh_y = np.meshgrid(x, x)
z = np.sinc((np.power(mesh_x, 2) + np.power(mesh_y, 2)))
z_norm = (z - z.min()) / (z.max() - z.min())
xyz = np.zeros((np.size(mesh_x), 3))
xyz[:, 0] = np.reshape(mesh_x, -1)
xyz[:, 1] = np.reshape(mesh_y, -1)
xyz[:, 2] = np.reshape(z_norm, -1)
print('xyz')
print(xyz)

From NumPy to open3d.PointCloud

Open3D 提供从 NumPy 矩阵到 3D 矢量矢量的转换。通过使用Vector3dVector ,NumPy 矩阵可以直接赋给open3d.PointCloud.points 。

通过这种方式,可以使用NumPy分配或修改任何类似的数据结构,例如open3d.PointCloud.colors或open3d.PointCloud.normals。下面的代码还将点云另存为ply文件,以供下一步使用。

# Pass xyz to Open3D.o3d.geometry.PointCloud and visualize
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz)
o3d.io.write_point_cloud("../../test_data/sync.ply", pcd)

From open3d.PointCloud to NumPy

如本示例所示,通过np.asarray将Vector3dVector类型的pcd_load.points转换为 NumPy 数组。

# Load saved point cloud and visualize it
pcd_load = o3d.io.read_point_cloud("../../test_data/sync.ply")

# Convert Open3D.o3d.geometry.PointCloud to numpy array
xyz_load = np.asarray(pcd_load.points)
print('xyz_load')
print(xyz_load)
o3d.visualization.draw_geometries([pcd_load])
相关文章
|
并行计算 PyTorch 算法框架/工具
Importing the numpy C-extensions failed.
Importing the numpy C-extensions failed.
1155 0
Importing the numpy C-extensions failed.
|
算法框架/工具
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
|
Python
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
203 0
|
机器学习/深度学习 TensorFlow 算法框架/工具
Tensorboard: No graph definition files were found
Tensorboard: No graph definition files were found
125 0
Tensorboard: No graph definition files were found
成功解决pandas\core\indexing.py:179: SettingWithCopyWarning: A value is trying to be set on a copy of a
成功解决pandas\core\indexing.py:179: SettingWithCopyWarning: A value is trying to be set on a copy of a
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\
成功解决Exception: Graph file doesn't exist, path=F:\File_Python\Python_example\Human_Posture_Detection\
|
Python
from scipy import special, optimize, from ._nnls import nnls ImportError: DLL load failed: 找不到指定的模块。
from scipy import special, optimize, from ._nnls import nnls ImportError: DLL load failed: 找不到指定的模块。
558 0
from scipy import special, optimize, from ._nnls import nnls ImportError: DLL load failed: 找不到指定的模块。
|
Python
Failed building wheel for scipy
Failed building wheel for scipy
484 0
|
缓存 Python
Python - with open()、os.open()、open()的详细使用
Python - with open()、os.open()、open()的详细使用
502 0
成功解决pandas\core\frame.py:2754: SettingWithCopyWarning: A value is trying to be set on a copy of a s
成功解决pandas\core\frame.py:2754: SettingWithCopyWarning: A value is trying to be set on a copy of a s
成功解决pandas\core\frame.py:2754: SettingWithCopyWarning: A value is trying to be set on a copy of a s