Reconstruct Mesh Using TSDF
SUMMARY
Reconstruct Mesh Using TSDF takes one depth image and one camera pose per camera, all of the same scene, and returns a triangle mesh of the observed surface together with the refined camera poses it was built with.
The Skill first refines the camera poses with point-to-plane ICP, absorbing hand-eye calibration and robot positioning errors of a few millimetres. It then fuses the depth images into a truncated signed distance function (TSDF) over the region of interest and extracts only surface that at least min_number_of_views cameras measured. Unlike reconstruct_mesh_using_poisson, it never invents surface where nothing was measured.
Use this Skill when you scan one object from several robot-held camera poses and want one clean mesh of it, for example a golden reference for visual inspection.
The Skill
from telekinesis import vitreous
reconstructed_mesh, refined_poses = vitreous.reconstruct_mesh_using_tsdf(
depth_images=depth_images,
intrinsic_matrix=intrinsic_matrix,
camera_to_world_transformation_matrices=camera_poses,
region_of_interest_oriented_bounding_box=region_of_interest,
)Data Transfer Notice
Every depth image is sent with the request: the 22 depth images of 968 x 602 pixels in the example are about 5 MB. Crop or subsample the images when the region of interest covers only part of them. The returned mesh is not decimated and can hold several hundred thousand triangles.
Example
Input
22 depth views of a metal bin taken by a robot-held camera.
Result
The mesh fused from the 22 views after the poses were refined: every surface appears once, and only surface seen by at least two views is kept.
The Code
import numpy as np
from telekinesis import datatypes, vitreous
# Load three overhead depth images of a metal bin. The PNGs store depth in
# tenths of a millimetre; 0 marks pixels without a measurement.
depth_images = [
datatypes.DepthImage.from_url(
f"https://assets.telekinesis.ai/examples/v1/depth_images/metal_bin/golden_bin_view_{index:02d}.png",
depth_scale=0.0001,
)
for index in range(3)
]
# Pinhole intrinsics shared by all views.
intrinsic_matrix = np.array(
[
[892.5320, 0.0000, 484.0409],
[0.0000, 892.5209, 300.8271],
[0.0000, 0.0000, 1.0000],
]
)
# Camera-to-world pose of each view, from the robot and its hand-eye
# calibration. The world frame is the robot base, in metres.
camera_poses = np.array(
[
[
[0.999982, 0.005909, -0.001212, 0.157029],
[0.005920, -0.999941, 0.009150, 0.707153],
[-0.001157, -0.009157, -0.999957, 0.592811],
[0.0, 0.0, 0.0, 1.0],
],
[
[0.999981, 0.005992, -0.001507, -0.058806],
[0.006008, -0.999927, 0.010480, 0.706391],
[-0.001444, -0.010489, -0.999944, 0.593981],
[0.0, 0.0, 0.0, 1.0],
],
[
[0.999980, 0.005901, -0.002144, -0.274562],
[0.005925, -0.999919, 0.011271, 0.705517],
[-0.002077, -0.011283, -0.999934, 0.594985],
[0.0, 0.0, 0.0, 1.0],
],
]
)
# World-frame box around the bin with a 1 cm margin:
# [cx, cy, cz, width, height, depth, roll, pitch, yaw] in metres and degrees.
region_of_interest = np.array(
[-0.0609, 0.7110, 0.0570, 0.6673, 0.3683, 0.1494, 0.5037, 0.2796, 0.1838]
)
# Run the skill. 2 mm voxels keep it fast; 1 mm resolves finer detail.
reconstructed_mesh, refined_poses = vitreous.reconstruct_mesh_using_tsdf(
depth_images=depth_images,
intrinsic_matrix=intrinsic_matrix,
camera_to_world_transformation_matrices=camera_poses,
region_of_interest_oriented_bounding_box=region_of_interest,
fusion_voxel_size=0.002,
truncation_distance=0.006,
)
# The mesh is in the world frame. refined_poses holds the (N, 4, 4) poses the
# depth images were fused with; compare them with the input poses to see how
# far each camera was moved.
vertices = reconstructed_mesh.vertex_positions
triangles = reconstructed_mesh.triangle_indices
camera_shifts = np.linalg.norm(
refined_poses.data[:, :3, 3] - camera_poses[:, :3, 3], axis=1
)Runnable examples are available in the Telekinesis examples repository.
Follow the README in that repository to set up the environment, then run this example with:
cd telekinesis-examples
python examples/point_cloud/reconstruct_mesh_using_tsdf.pyParameter Configuration
The first four parameters describe the scan. The next eight control the pose refinement, and the last five control the TSDF fusion and which surface is kept.
| Parameter | Type | Default | Description |
|---|---|---|---|
depth_images | datatypes.ImageBatch | list[datatypes.DepthImage | np.ndarray] | required | One (H, W) depth image per camera, in metres along the optical axis. Pixels that are zero, negative or not finite are ignored. At least two are required |
intrinsic_matrix | datatypes.Mat3x3 | np.ndarray | required | The (3, 3) pinhole intrinsic matrix shared by all depth images |
camera_to_world_transformation_matrices | datatypes.Array | np.ndarray | required | The (N, 4, 4) initial camera poses, one per depth image, each mapping camera-frame points into the world frame (metres) |
region_of_interest_oriented_bounding_box | datatypes.OrientedBox3D | np.ndarray | required | World-frame box [cx, cy, cz, width, height, depth, roll_deg, pitch_deg, yaw_deg] (Euler XYZ, degrees). Only depth inside it is used, and the voxel grid spans it, aligned with its edges |
downsampling_voxel_size | datatypes.Float | float | int | 0.003 | Voxel edge length, in metres, the points are downsampled to for the pose refinement. Must be > 0 |
max_correspondence_distance | datatypes.Float | float | int | 0.006 | Largest distance, in metres, between a point and its correspondence in the pose refinement; larger pose errors cannot be corrected. Must be > 0 |
normal_search_radius | datatypes.Float | float | int | 0.01 | Radius, in metres, of the neighbourhood used to estimate surface normals in the pose refinement. Must be > 0 |
normal_max_neighbors | datatypes.Int | int | 30 | Largest number of neighbours used to estimate a surface normal in the pose refinement. Must be > 0 |
max_iterations | datatypes.Int | int | 50 | Largest number of iterations of each ICP alignment. Must be > 0 |
number_of_refinement_rounds | datatypes.Int | int | 3 | Number of pose refinement passes over all cameras. Must be > 0 |
max_correction_translation | datatypes.Float | float | int | 0.008 | Largest accumulated translation, in metres, of a camera's pose correction, measured in the region-of-interest frame. Must be > 0 |
max_correction_rotation_degrees | datatypes.Float | float | int | 2.5 | Largest accumulated rotation, in degrees, of a camera's pose correction. Must be > 0 |
fusion_voxel_size | datatypes.Float | float | int | 0.001 | Edge length, in metres, of the TSDF voxels; the finest detail the mesh can resolve. Must be > 0 |
truncation_distance | datatypes.Float | float | int | 0.004 | Distance, in metres, from a measured surface within which a depth image updates voxels. Must be > 0 |
min_ray_surface_cosine | datatypes.Float | float | int | 0.15 | Smallest cosine between a pixel ray and the measured surface normal for the pixel to be fused. Must be within [0, 1] |
min_observation_weight | datatypes.Float | float | int | 0.3 | Smallest accumulated cosine weight for a voxel to be trusted. Must be >= 0 |
min_number_of_views | datatypes.Int | int | 2 | Smallest number of depth images that must have measured a voxel for it to be trusted. Must be > 0 |
Returns
A 2-tuple:
| Type | Description |
|---|---|
datatypes.Mesh3D | reconstructed_mesh: the observed surface in the world frame, with vertex normals. It keeps every trusted surface inside the region of interest, including the supporting table, and is not decimated |
datatypes.Array | refined_camera_to_world_transformation_matrices: the (N, 4, 4) refined camera poses the depth images were fused with. A camera whose correction exceeded a limit in every round keeps its input pose. Use .data for the raw array |
Raises
| Exception | Condition |
|---|---|
TypeError | A parameter's value does not match its expected type (see the Parameter Configuration table above) |
ValueError | Fewer than two depth images are given, the numbers of depth images and poses differ, a pose is not finite or not (4, 4), or a numeric parameter is out of range |
ConfigurationError | The TELEKINESIS_API_KEY environment variable is not set |
SerializationError | The request input failed to serialize, the response was not returned as an Arrow stream, or the response failed to deserialize |
RequestTimeoutError | The request to the Vitreous service timed out |
TransportError | A network failure occurred before a response was received |
ClientError | The Vitreous service rejected the request due to invalid or malformed input (HTTP 400/422), for example when no depth falls inside the region of interest or no surface was measured by min_number_of_views views, an unrecognized endpoint (HTTP 404), or another unexpected 4xx response |
AuthenticationError | The API key was rejected as invalid or expired (HTTP 401) |
AuthenticationServiceError | The authentication service returned an invalid response, was temporarily unavailable, or timed out (HTTP 502/503/504) |
ServerError | The Vitreous service returned a 5xx or otherwise unexpected error response |
How to Tune the Parameters
The defaults suit a structured-light or stereo camera about 0.6 m from a part of tens of centimetres, with pose errors of a few millimetres.
region_of_interest_oriented_bounding_box
- Controls: Which depth takes part, the frame the pose correction limits are measured in, and the extent and orientation of the voxel grid.
- Units: Metres for the centre and size, degrees for the rotation
- Default: none (required)
- Enclose the object with a margin of about 1 cm and leave out the cell around it: points that move with the robot or are seen by only one camera pull the pose alignment. Memory and run time grow with the box volume divided by the cube of
fusion_voxel_size: a 0.62 x 0.37 x 0.15 m box at 1 mm voxels has about 34 million voxels.
Pose Refinement
max_correspondence_distance
- Controls: How far apart a point and its correspondence may be in the pose alignment.
- Units: Metres
- Default:
0.006 - Increase → corrects larger pose errors, but risks wrong correspondences between nearby surfaces
- Decrease → stricter matching, only for poses that are already close
- Set to about twice the largest expected pose error at the object.
downsampling_voxel_size
- Controls: The point spacing used for the pose alignment.
- Units: Metres
- Default:
0.003 - Increase → faster, coarser alignment
- Decrease → slower, uses finer detail
- Keep it at about half of
max_correspondence_distanceor less.
normal_search_radius and normal_max_neighbors
- Control: The neighbourhood used to estimate the surface normals that point-to-plane ICP measures distances along.
- Units: Metres for the radius; a count of points for the neighbours
- Default:
0.01and30 - Increase → smoother, more stable normals, but edges and small features are rounded off
- Decrease → normals follow finer detail, but become noisy
- Set the radius to about three times
downsampling_voxel_size.
number_of_refinement_rounds and max_iterations
- Control: How often every camera is realigned, and how long each alignment may run.
- Units: Counts
- Default:
3and50 - Increase → more time for the cameras to settle, at a higher run time
- Decrease → faster, but the poses may not converge
- Later rounds let every camera settle against the others' corrections; three rounds usually converge. Each round runs one ICP per camera against all other cameras, so the time grows with the number of cameras squared.
max_correction_translation and max_correction_rotation_degrees
- Control: How far a camera may be moved in total.
- Units: Metres and degrees
- Default:
0.008and2.5 - Increase → larger pose errors can be corrected, but a camera that does not fit the others can be pulled further
- Decrease → cameras stay closer to their input poses
- Set them a little above the largest pose error you expect. A camera that would move further keeps its previous correction and its rejection is counted, so a camera that does not fit the others is never pulled far.
Fusion
fusion_voxel_size
- Controls: The resolution of the mesh.
- Units: Metres
- Default:
0.001 - Increase → faster, less memory, smoother and coarser mesh
- Decrease → finer detail, but memory and run time grow with the cube of the inverse
- Keep it at or above the pixel spacing of the depth images at the object (distance divided by the focal length in pixels: about 0.7 mm at 0.6 m for a camera with an 890 px focal length). Each pixel updates only the voxels along its own ray, so smaller voxels leave holes in the mesh.
truncation_distance
- Controls: How far from a measured surface each image updates voxels.
- Units: Metres
- Default:
0.004 - Increase → tolerates more depth noise and residual pose error, but surfaces closer together than this (the two sides of a thin wall) partly cancel
- Decrease → keeps thin features apart, but noisy surfaces break up
- Keep it at two to four times
fusion_voxel_size.
min_ray_surface_cosine
- Controls: How grazing a view of a surface may be and still be fused.
- Units: Cosine of the angle between the pixel ray and the surface normal (dimensionless)
- Default:
0.15(about 81° from the surface normal) - Increase → only steep views are fused, which removes depth that is unreliable at grazing angles but can leave walls unobserved
- Decrease → grazing views are fused too, which fills walls seen only at a shallow angle with noisier depth
min_number_of_views and min_observation_weight
- Control: How much evidence a voxel needs before surface is extracted there.
- Units: A count of depth images; an accumulated cosine weight (dimensionless)
- Default:
2and0.3 - Increase
min_number_of_views→ fewer reflections and artefacts seen by a single camera, but surface seen by fewer cameras is left out as unobserved - Increase
min_observation_weight→ surface seen only at grazing angles is left out 1keeps everything any camera measured;2is the usual choice for reflective parts.
TIP
Best practice: compare the returned poses with the input poses. A camera that kept exactly its input pose while the others moved, or one that moved almost as far as max_correction_translation, does not fit the others well; exclude or recapture it and reconstruct again.
Where to Use the Skill
Common pipelines include:
- Golden-sample enrollment for visual inspection – build a sharp reference mesh from many views of an approved part.
- Multi-view 3D scanning – turn robot-held depth views of an object into one mesh.
- Reverse engineering and digitization – capture the geometry of a part for comparison with CAD or for simulation.
After the reconstruction, reduce the triangle count with filter_mesh_using_quadric_decimation when a lighter mesh is needed.
Alternative Skills
| Skill | Comparison with Reconstruct Mesh Using TSDF |
|---|---|
| reconstruct_mesh_using_poisson | Fits a smooth surface through a point cloud with normals. It closes gaps where nothing was measured, which suits visualization but can hide missing or dented areas; this Skill keeps only measured surface. |
When Not to Use the Skill
Do not use Reconstruct Mesh Using TSDF when:
- The camera poses are unknown or more than
max_correspondence_distanceoff – establish a coarse alignment first. - You only have point clouds without their depth images – the fusion needs each pixel's ray; use
reconstruct_mesh_using_poissonon the point cloud instead. - The object has walls thinner than
truncation_distanceseen from both sides – both sides fall into the same band and partly cancel; reducetruncation_distanceandfusion_voxel_size. - You need a watertight mesh – surface that no camera (or fewer than
min_number_of_viewscameras) measured stays open.