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.
1341 0
Importing the numpy C-extensions failed.
|
6月前
|
传感器 数据可视化 索引
Open3D Ray Casting 光线投射
Open3D Ray Casting 光线投射
125 2
|
7月前
|
Python
python中 open() 和 File()
在Python中,open()是内置函数,而File是类。它们的区别和理解如下: 1. open()函数:open()函数用于打开一个文件,并返回一个文件对象。它有以下几个参数:
83 2
成功解决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
|
机器学习/深度学习 TensorFlow 算法框架/工具
Tensorboard: No graph definition files were found
Tensorboard: No graph definition files were found
156 0
Tensorboard: No graph definition files were found
成功解决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
Python - with open()、os.open()、open()的详细使用
Python - with open()、os.open()、open()的详细使用
530 0
成功解决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\
|
Java Linux
too many open files
If you encounter the file descriptor leaks problem, it might be helpful to you.
2533 0
|
存储 传感器 移动开发
浅析Numpy.genfromtxt及File I/O讲解
Python 并没有提供数组功能,虽然列表 (list) 可以完成基本的数组功能,但它并不是真正的数组,而且在数据量较大时,使用列表的速度就会慢的让人难受。为此,Numpy 提供了真正的数组功能,以及对数据快速处理的函数。
1218 0