Expand
Example A : Perform registration with numpy arrays
# Align two point clouds using various ICP-like algorithms.
#
# Parameters
# ----------
# target_points : NDArray[np.float64]
# Nx3 or Nx4 matrix representing the target point cloud.
# source_points : NDArray[np.float64]
# Nx3 or Nx4 matrix representing the source point cloud.
# init_T_target_source : np.ndarray[np.float64]
# 4x4 matrix representing the initial transformation from target to source.
# registration_type : str = 'GICP'
# Type of registration algorithm to use ('ICP', 'PLANE_ICP', 'GICP', 'VGICP').
# voxel_resolution : float = 1.0
# Resolution of voxels used for correspondence search (used only in VGICP).
# downsampling_resolution : float = 0.25
# Resolution for downsampling the point clouds.
# max_correspondence_distance : float = 1.0
# Maximum distance for matching points between point clouds.
# num_threads : int = 1
# Number of threads to use for parallel processing.
#
# Returns
# -------
# RegistrationResult
# Object containing the final transformation matrix and convergence status.
result = small_gicp.align(target_raw_numpy, source_raw_numpy, downsampling_resolution=0.25)
result.T_target_source # Estimated transformation (4x4 numpy array)
result.converged # If true, the optimization converged successfully
result.iterations # Number of iterations the optimization took
result.num_inliers # Number of inlier points
result.H # Final Hessian matrix (6x6 matrix)
result.b # Final information vector (6D vector)
result.e # Final error (float)
Example B : Perform preprocessing and registration separately
# Preprocess point cloud (downsampling, kdtree construction, and normal/covariance estimation)
#
# Parameters
# ----------
# points : NDArray[np.float64]
# Nx3 or Nx4 matrix representing the point cloud.
# downsampling_resolution : float = 0.1
# Resolution for downsampling the point clouds.
# num_neighbors : int = 20
# Number of neighbor points to usefor point normal/covariance estimation.
# num_threads : int = 1
# Number of threads to use for parallel processing.
#
# Returns
# -------
# PointCloud
# Downsampled point cloud with estimated normals and covariances.
# KdTree
# KdTree for the downsampled point cloud
target, target_tree = small_gicp.preprocess_points(target_raw_numpy, downsampling_resolution=0.25)
source, source_tree = small_gicp.preprocess_points(source_raw_numpy, downsampling_resolution=0.25)
# `target` and `source` are small_gicp.PointCloud with the following methods
target.size() # Number of points
target.points() # Nx4 numpy array [x, y, z, 1] x N
target.normals() # Nx4 numpy array [nx, ny, nz, 0] x N
target.covs() # Array of 4x4 covariance matrices
# Align two point clouds using specified ICP-like algorithms, utilizing point cloud and KD-tree inputs.
#
# Parameters
# ----------
# target : PointCloud::ConstPtr
# Pointer to the target point cloud.
# source : PointCloud::ConstPtr
# Pointer to the source point cloud.
# target_tree : KdTree<PointCloud>::ConstPtr, optional
# Pointer to the KD-tree of the target for nearest neighbor search. If nullptr, a new tree is built.
# init_T_target_source : NDArray[np.float64]
# 4x4 matrix representing the initial transformation from target to source.
# registration_type : str = 'GICP'
# Type of registration algorithm to use ('ICP', 'PLANE_ICP', 'GICP').
# max_correspondence_distance : float = 1.0
# Maximum distance for corresponding point pairs.
# num_threads : int = 1
# Number of threads to use for computation.
#
# Returns
# -------
# RegistrationResult
# Object containing the final transformation matrix and convergence status.
result = small_gicp.align(target, source, target_tree)
Example C : Perform each of preprocessing steps one-by-one
# Convert numpy arrays (Nx3 or Nx4) to small_gicp.PointCloud
target_raw = small_gicp.PointCloud(target_raw_numpy)
source_raw = small_gicp.PointCloud(source_raw_numpy)
# Downsampling
target = small_gicp.voxelgrid_sampling(target_raw, 0.25)
source = small_gicp.voxelgrid_sampling(source_raw, 0.25)
# KdTree construction
target_tree = small_gicp.KdTree(target)
source_tree = small_gicp.KdTree(source)
# Estimate covariances
small_gicp.estimate_covariances(target, target_tree)
small_gicp.estimate_covariances(source, source_tree)
# Align point clouds
result = small_gicp.align(target, source, target_tree)
Example D: Example with Open3D
target_o3d = open3d.io.read_point_cloud('small_gicp/data/target.ply').paint_uniform_color([0, 1, 0])
source_o3d = open3d.io.read_point_cloud('small_gicp/data/source.ply').paint_uniform_color([0, 0, 1])
target, target_tree = small_gicp.preprocess_points(numpy.asarray(target_o3d.points), downsampling_resolution=0.25)
source, source_tree = small_gicp.preprocess_points(numpy.asarray(source_o3d.points), downsampling_resolution=0.25)
result = small_gicp.align(target, source, target_tree)
source_o3d.transform(result.T_target_source)
open3d.visualization.draw_geometries([target_o3d, source_o3d])