trimesh.registration¶
registration.py¶
Functions for registering (aligning) point clouds with meshes.
-
trimesh.registration.
icp
(a, b, initial=array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]]), threshold=1e-05, max_iterations=20, **kwargs)¶ Apply the iterative closest point algorithm to align a point cloud with another point cloud or mesh. Will only produce reasonable results if the initial transformation is roughly correct. Initial transformation can be found by applying Procrustes’ analysis to a suitable set of landmark points (often picked manually).
- Parameters
a ((n,3) float) – List of points in space.
b ((m,3) float or Trimesh) – List of points in space or mesh.
initial ((4,4) float) – Initial transformation.
threshold (float) – Stop when change in cost is less than threshold
max_iterations (int) – Maximum number of iterations
kwargs (dict) – Args to pass to procrustes
- Returns
matrix ((4,4) float) – The transformation matrix sending a to b
transformed ((n,3) float) – The image of a under the transformation
cost (float) – The cost of the transformation
-
trimesh.registration.
mesh_other
(mesh, other, samples=500, scale=False, icp_first=10, icp_final=50)¶ Align a mesh with another mesh or a PointCloud using the principal axes of inertia as a starting point which is refined by iterative closest point.
- Parameters
mesh (trimesh.Trimesh object) – Mesh to align with other
other (trimesh.Trimesh or (n, 3) float) – Mesh or points in space
samples (int) – Number of samples from mesh surface to align
scale (bool) – Allow scaling in transform
icp_first (int) – How many ICP iterations for the 9 possible combinations of sign flippage
icp_final (int) – How many ICP iterations for the closest candidate from the wider search
- Returns
mesh_to_other ((4, 4) float) – Transform to align mesh to the other object
cost (float) – Average squared distance per point
-
trimesh.registration.
procrustes
(a, b, reflection=True, translation=True, scale=True, return_cost=True)¶ Perform Procrustes’ analysis subject to constraints. Finds the transformation T mapping a to b which minimizes the square sum distances between Ta and b, also called the cost.
- Parameters
a ((n,3) float) – List of points in space
b ((n,3) float) – List of points in space
reflection (bool) – If the transformation is allowed reflections
translation (bool) – If the transformation is allowed translations
scale (bool) – If the transformation is allowed scaling
return_cost (bool) – Whether to return the cost and transformed a as well
- Returns
matrix ((4,4) float) – The transformation matrix sending a to b
transformed ((n,3) float) – The image of a under the transformation
cost (float) – The cost of the transformation