text
stringlengths
0
1.47k
object-tuned ``feature_align`` seed lands 90-170 deg off on 3DMatch. The robust seed instead
follows Open3D's recipe (voxel → normals 2·voxel → FPFH 5·voxel), so the only scale knob is the
voxel. A bbox/N**(1/3) estimate badly over-coarsens here (two not-yet-registered fragments span
a ~5 m union box but each is a sparse ~5 k-point scan, giving a useless ~0.28 m voxel). The
correct, density-following scale is the cloud's own point spacing: take the median nearest-
neighbour distance and scale it (``mult``) so a few points fall per voxel. This recovers ≈0.05 m
on the (already 5 cm-decimated) 3DMatch fragments, Open3D's proven setting, and still adapts
down to a dense 14 cm object. Returns a positive metre voxel.
"""
n = pts.shape[0]
if n < 4:
return 0.05
# median nearest-neighbour distance on a strided subsample (cheap, scale-following).
sub = _stride_subsample(pts, min(n, 2000)).to(torch.float32)
d = torch.cdist(sub, sub)
d.fill_diagonal_(float("inf"))
nn = d.min(dim=1).values
spacing = float(nn.median().item())
if not math.isfinite(spacing) or spacing <= 0.0:
ext = (pts.amax(dim=0) - pts.amin(dim=0)).clamp_min(0.0)
return float(max(float(ext.norm().item()) / 50.0, 1e-4))
return float(max(spacing * mult, 1e-4))
def _open3d_fpfh_ransac_seed(
src: torch.Tensor, tgt: torch.Tensor, voxel: float, rng_seed: int = 42
) -> tuple[torch.Tensor | None, int]:
"""Classical FPFH + RANSAC global seed via Open3D (source→target 4×4), or ``None`` if unavailable.
Matches the proven Open3D ``registration_ransac_based_on_feature_matching`` recipe (Choi et al.
2015 / the Open3D global-registration tutorial): voxel downsample, normals at radius ``2*voxel``,
FPFH at radius ``5*voxel``, mutual-filter RANSAC over 4-point samples with edge-length + distance
correspondence checkers and 100k/0.999 convergence. This is scale-correct (radii follow the
auto ``voxel``) and is the robustness Open3D itself reports (~77 % RR on 3DMatch), splatreg then
refines it for accuracy and (optionally) scale. Returns ``(T, n_corr)``; ``n_corr`` is the size
of the RANSAC correspondence set (a coarse seed-quality signal).
"""
try:
import open3d as o3d # optional dependency; pure-splatreg path used when absent
except Exception:
return None, 0
import numpy as _np
sp_np = src.detach().cpu().to(torch.float64).numpy()
tp_np = tgt.detach().cpu().to(torch.float64).numpy()
def _prep(p):
pc = o3d.geometry.PointCloud()
pc.points = o3d.utility.Vector3dVector(p)
# NB: the input clouds are already voxel-decimated by the caller; an extra voxel_down_sample
# here only throws away the correspondences RANSAC needs, so we estimate features directly.
pc.estimate_normals(o3d.geometry.KDTreeSearchParamHybrid(radius=voxel * 2.0, max_nn=30))
fpfh = o3d.pipelines.registration.compute_fpfh_feature(
pc, o3d.geometry.KDTreeSearchParamHybrid(radius=voxel * 5.0, max_nn=100)
)
return pc, fpfh
try:
# Determinism: Open3D's RANSAC draws minimal samples from a global RNG, so without a fixed
# seed the recovered pose is non-deterministic across runs (a bad draw once hit 117 deg where
# clean reruns sit at ~11 deg). ``o3d.utility.random.seed`` is the only knob — this overload
# of ``registration_ransac_based_on_feature_matching`` exposes no per-call seed argument.
o3d.utility.random.seed(int(rng_seed))
sp, sf = _prep(sp_np)
tp, tf = _prep(tp_np)
dist = voxel * 1.5
res = o3d.pipelines.registration.registration_ransac_based_on_feature_matching(
sp,
tp,
sf,
tf,
True, # mutual filter
dist,
o3d.pipelines.registration.TransformationEstimationPointToPoint(False),
3,
[
o3d.pipelines.registration.CorrespondenceCheckerBasedOnEdgeLength(0.9),
o3d.pipelines.registration.CorrespondenceCheckerBasedOnDistance(dist),
],
o3d.pipelines.registration.RANSACConvergenceCriteria(100000, 0.999),
)
T = torch.tensor(_np.asarray(res.transformation), dtype=torch.float64)
return T, int(len(res.correspondence_set))
except Exception:
return None, 0
def _open3d_icp_refine(
src: torch.Tensor, tgt: torch.Tensor, T0: torch.Tensor, voxel: float, iters: int = 50
) -> torch.Tensor | None:
"""Open3D point-to-plane ICP local refine of a global seed (source→target 4×4), or ``None``.
Standard scale-correct local refinement: point-to-plane ICP at a ``2*voxel`` max-correspondence
distance with the seed as the initialisation. This is the Open3D global-registration tutorial's
own refine step; it tightens a good FPFH+RANSAC seed without the object-scale failure mode of the
overlap ICP tuned for 14 cm splats (which wanders on low-overlap room scans). Returns the refined
4×4, or ``None`` to signal "keep the seed".
"""
try:
import open3d as o3d