Open3D is an open-source library that supports rapid development of software that deals with 3D data. The Open3D frontend exposes a set of carefully selected data structures and algorithms in both C++ and Python. The backend is highly optimized and is set up for parallelization.
-- Mouse view control -- Left button + drag : Rotate. Ctrl + left button + drag : Translate. Wheel button + drag : Translate. Shift + left button + drag : Roll. Wheel : Zoom in/out.
-- Keyboard view control -- [/] : Increase/decrease field of view. R : Reset view point. Ctrl/Cmd + C : Copy current view status into the clipboard. Ctrl/Cmd + V : Paste view status from clipboard.
-- General control -- Q, Esc : Exit window. H : Print help message. P, PrtScn : Take a screen capture. D : Take a depth capture. O : Take a capture of current rendering settings.
print("Downsample the point cloud with a voxel of 0.05") downpcd = pcd1.voxel_down_sample(voxel_size=0.05) o3d.visualization.draw_geometries([downpcd]) print("The number of PC is : ",pcd1) print("The number of downPC is : ",downpcd)
''' Downsample the point cloud with a voxel of 0.05 The number of PC is : PointCloud with 10000 points. The number of downPC is : PointCloud with 1389 points. Downsample the point cloud with a voxel of 0.005 The number of PC is : PointCloud with 10000 points. The number of downPC is : PointCloud with 9825 points. '''
print("Recompute the normal of the downsampled point cloud") downpcd.estimate_normals( search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.1, max_nn=30)) o3d.visualization.draw_geometries([downpcd], zoom=0.3412, front=[0.4257, -0.2125, -0.8795], lookat=[2.6172, 2.0475, 1.532], up=[-0.0694, -0.9768, 0.2024], point_show_normal=True)
如果想要访问顶点法线的话,可以直接通过索引获取:
1 2 3 4 5 6 7
print("Print a normal vector of the 0th point") print(downpcd.normals[0])
''' Print a normal vector of the 0th point [ 0.99552379 -0.03798043 0.08654404] '''
也可以将其转为numpy数组:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
print("Print the normal vectors of the first 10 points") print(np.asarray(downpcd.normals)[:10, :])
''' Print the normal vectors of the first 10 points [[ 0.99552379 -0.03798043 0.08654404] [-0.00180642 -0.97317626 0.23005372] [-0.03311035 0.95990356 -0.27836821] [-0.18007638 -0.98233851 -0.05082867] [ 0.03201738 -0.92865206 0.36956763] [-0.09411325 0.9584897 -0.26914715] [-0.00804695 0.97716482 -0.21233029] [-0.95046739 -0.20590633 0.2328397 ] [ 0.58566868 0.7923609 0.17075245] [-0.19273423 -0.87191173 0.45013714]] '''
print("Load a polygon volume and use it to crop the original point cloud") demo_crop_data = o3d.data.DemoCropPointCloud() pcd = o3d.io.read_point_cloud(demo_crop_data.point_cloud_path) vol = o3d.visualization.read_selection_polygon_volume(demo_crop_data.cropped_json_path) chair = vol.crop_point_cloud(pcd) o3d.visualization.draw_geometries([chair], zoom=0.7, front=[0.5439, -0.2333, -0.8060], lookat=[2.4615, 2.1331, 1.338], up=[-0.1781, -0.9708, 0.1608])
inner=pcd1.select_by_index([i for i inrange(len(pcd1.points)) if i%2==0]) outer=pcd1.select_by_index([i for i inrange(10)],invert=True) o3d.visualization.draw_geometries([pcd1]) o3d.visualization.draw_geometries([inner]) o3d.visualization.draw_geometries([outer])
Open3D支持使用RANSAC方法从点云中分割几何基元(geometric primitives)。通过segment_plane方法,可以找到点云中的最大支持平面(the plane with the largest support)。该方法提供了三个参数:
distance_threshold:定义了一个点可被视为内嵌点的估计平面的最大距离
ransac_n:定义用来估计平面的随机抽样点数量
num_iterations:定义了随机平面抽样和验证的频率
4.6 消隐点
当我们从给定视角渲染点云时,由于前方没有遮挡,可能会有背面的点渗入到前景中。Katz提出了一种消隐算法(Hidden point removal),可以从给定的视图中近似地获得点云的可见性,而无需表面重建或正常的估计。
1 2 3 4 5 6 7 8 9
print("Convert mesh to a point cloud and estimate dimensions") armadillo = o3d.data.ArmadilloMesh() mesh = o3d.io.read_triangle_mesh(armadillo.path) mesh.compute_vertex_normals()