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.
1216 0
Importing the numpy C-extensions failed.
|
2月前
|
数据处理 Python
【Python】已解决:raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+‘; not supported’) xlrd.biffh.XLRD
【Python】已解决:raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+‘; not supported’) xlrd.biffh.XLRD
51 1
|
2月前
|
开发者 Python
【Python】已解决:(pandas read_excel 读取Excel报错)ImportError: Pandas requires version ‘2.0.1’ or newer of ‘x
【Python】已解决:(pandas read_excel 读取Excel报错)ImportError: Pandas requires version ‘2.0.1’ or newer of ‘x
75 0
|
2月前
|
计算机视觉 索引 Python
【Python】已解决:ERROR: Could not find a version that satisfies the requirement cv2 (from versions: none)
【Python】已解决:ERROR: Could not find a version that satisfies the requirement cv2 (from versions: none)
56 0
|
2月前
|
数据库 开发工具 开发者
【Python】已解决:You have 18 unapplied migration(s). Your project may not work properly until you apply t
【Python】已解决:You have 18 unapplied migration(s). Your project may not work properly until you apply t
49 0
|
Python
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
【python3.6】pyinstaller报错AssertionError: Failed to determine matplotlib‘s data directory!【解决方案】
249 0
|
机器学习/深度学习 TensorFlow 算法框架/工具
Tensorboard: No graph definition files were found
Tensorboard: No graph definition files were found
141 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
|
计算机视觉 Python
Python安装cv2库出错及解决:Could not find a version that satisfies the requirement cv2
Python安装cv2库出错及解决:Could not find a version that satisfies the requirement cv2
621 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\