Ejemplo n.º 1
0
how many points are sampled from the triangle surface.
'''
mesh = o3d.geometry.TriangleMesh.create_sphere()
mesh.compute_vertex_normals()
o3d.visualization.draw_geometries([mesh],
                                  width=800,
                                  height=600,
                                  window_name='Mesh with Normal')

pcd = mesh.sample_points_uniformly(number_of_points=500)
o3d.visualization.draw_geometries([pcd],
                                  width=800,
                                  height=600,
                                  window_name='Meshed Point Cloud')

mesh = o3dtut.get_bunny_mesh()
mesh.compute_vertex_normals()
o3d.visualization.draw_geometries([mesh],
                                  width=800,
                                  height=600,
                                  window_name='Mesh with Normal')

pcd = mesh.sample_points_uniformly(number_of_points=500)
o3d.visualization.draw_geometries([pcd],
                                  width=800,
                                  height=600,
                                  window_name='Meshed Point Cloud')
'''
Uniform sampling can yield clusters of points on the surface, while a method called Poisson disk sampling can evenly
distribute the points on the surface. The method sample_points_poisson_disk implements sample elimination. It starts
with a sampled point cloud and removes points to satisfy the sampling criterion. The method supports two options to
Ejemplo n.º 2
0
########################################################################################################################
'''
Point clouds and triangle meshes are very flexible, but irregular, geometry types. The voxel grid is another geometry
type in 3D that is defined on a regular 3D grid, whereas a voxel can be thought of as the 3D counterpart to the pixel
in 2D. Open3D has the geometry type VoxelGrid that can be used to work with voxel grids.
'''
########################################################################################################################
# 2. From triangle mesh
########################################################################################################################
'''
Open3D provides the method create_from_triangle_mesh that creates a voxel grid from a triangle mesh. It returns a voxel
grid where all voxels that are intersected by a triangle are set to 1, all others are set to 0. The argument voxel_size
defines the resolution of the voxel grid.
'''
print('input')
mesh = o3dtut.get_bunny_mesh()
# fit to unit cube
mesh.scale(1 / np.max(mesh.get_max_bound() - mesh.get_min_bound()),
           center=mesh.get_center())
o3d.visualization.draw_geometries([mesh],
                                  width=800,
                                  height=600,
                                  window_name='Triangle')

print('voxelization')
voxel_grid = o3d.geometry.VoxelGrid.create_from_triangle_mesh(mesh,
                                                              voxel_size=0.05)
o3d.visualization.draw_geometries([voxel_grid],
                                  width=800,
                                  height=600,
                                  window_name='Voxel Grid from triangle')
                                  zoom=0.7,
                                  width=800, height=600,
                                  window_name='Bounding volumes',
                                  front=[0.5439, -0.2333, -0.8060],
                                  lookat=[2.4615, 2.1331, 1.338],
                                  up=[-0.1781, -0.9708, 0.1608])

########################################################################################################################
# 9. Convex hull
########################################################################################################################
'''
The convex hull of a point cloud is the smallest convex set that contains all points. Open3D contains the method
compute_convex_hull that computes the convex hull of a point cloud. The implementation is based on
Qhull(http://www.qhull.org/).
'''
pcl = o3dtut.get_bunny_mesh().sample_points_poisson_disk(number_of_points=2000)
hull, _ = pcl.compute_convex_hull()
hull_ls = o3d.geometry.LineSet.create_from_triangle_mesh(hull)
hull_ls.paint_uniform_color((1, 0, 0))
o3d.visualization.draw_geometries([pcl, hull_ls],
                                  width=800, height=600,
                                  window_name='Convex hull')

########################################################################################################################
# 10. DBSCAN clustering
########################################################################################################################
'''
Given a point cloud from e.g. a depth sensor we want to group local point cloud clusters together. For this purpose, we
can use clustering algorithms. Open3D implements DBSCAN [Ester1996] that is a density based clustering algorithm. The
algorithm is implemented in cluster_dbscan and requires two parameters: eps defines the distance to neighbors in a
cluster and min_points defines the minimum number of points required to form a cluster. The function returns labels,