feat: apply work-plane filter at all three cloud sites

points_via_sam21, _points_via_bbox, and _object_cloud_cv (bbox branch)
now call apply_below_plane_filter on the CV-frame cloud before the
<10-points guard. Responses carry plane_applied + n_points_before_plane.
Without a saved plane the filter is a no-op (plane_applied=false).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Adriano Dal PastroandClaude Opus 4.7 committed 2026-05-11 16:52:17 +02:00
1 parent 28ba0dd9f2
commit 3b0a65554a
3 files changed
+50 -17

No files matched your search

+14 -4
View File
@@ -17,6 +17,7 @@ from ..clients import NuwaError, Sam21Error, Sam21Unavailable
from ..timing import Stopwatch
from .depth_align import align_depth_to_rgb
from .depth_to_rgb import CameraRegistration
from .work_plane import apply_below_plane_filter, get_work_plane
log = logging.getLogger(__name__)
@@ -31,13 +32,17 @@ SAM21_BUG_CODES = frozenset({"SHAPE_MISMATCH", "BBOX_OUT_OF_BOUNDS",
def points_via_sam21(nuwa, sam21, bbox: tuple[int, int, int, int],
sw: Stopwatch) -> np.ndarray:
sw: Stopwatch) -> tuple[np.ndarray, dict]:
"""SAM21 path: bbox → segmented point cloud in RGB-camera/OpenCV frame.
Returns points in **meters**. Raises Sam21Fallback on failures that
should trigger the bbox path. Re-raises HTTPException(502) for Nuwa
failures (the bbox path would fail too — better to fail fast). All
SAM21-specific logging happens here; callers do not log on fallback.
After the SAM21 segmentation the work-plane filter is applied (no-op if no
plane is calibrated). Returns (points, plane_info) where plane_info has
`plane_applied` and `n_points_before_plane`.
"""
try:
with sw.step("nuwa_grab"):
@@ -120,7 +125,12 @@ def points_via_sam21(nuwa, sam21, bbox: tuple[int, int, int, int],
log.error("Unexpected SAM21 error: %r", e)
raise Sam21Fallback(f"unexpected: {e!r}") from e
pts_cv, plane_info = apply_below_plane_filter(pts_cv, get_work_plane())
if pts_cv.shape[0] < 10:
log.warning("SAM21 returned %d points (<10), falling back to bbox", pts_cv.shape[0])
raise Sam21Fallback(f"too few points: {pts_cv.shape[0]}")
return pts_cv
log.warning("SAM21 cloud has %d points after plane filter (<10), falling back to bbox",
pts_cv.shape[0])
raise Sam21Fallback(
f"too few points after plane filter: {pts_cv.shape[0]}"
f" (before plane: {plane_info['n_points_before_plane']})"
)
return pts_cv, plane_info