diff --git a/src/presa_mano/api/grasp_routes.py b/src/presa_mano/api/grasp_routes.py index 23208b7..2318fe2 100644 --- a/src/presa_mano/api/grasp_routes.py +++ b/src/presa_mano/api/grasp_routes.py @@ -65,9 +65,26 @@ def _object_points_in_base(conf: float | None, class_name: str | None, sw: Stopw raise HTTPException(status_code=404, detail="no object detected") dets.sort(key=lambda d: d["confidence"], reverse=True) top = dets[0] - b = top["bbox"] + bbox = _bbox_to_roi(top["bbox"]) - u_min, v_min, u_max, v_max = _bbox_to_roi(b) + pts_base = _points_via_bbox(nuwa, T_base_cam, bbox, sw) + meta = { + "detection": top, + "T_base_camera": T_base_cam.tolist(), + "n_points": int(len(pts_base)), + "source": "bbox_roi", + } + return pts_base, meta + + +def _points_via_bbox(nuwa, T_base_cam: np.ndarray, bbox: tuple[int, int, int, int], + sw: Stopwatch) -> np.ndarray: + """Legacy path: bbox → Nuwa ROI cloud → filter outliers → base frame. + + Raises HTTPException(422) on <10 valid depth points (existing behaviour). + """ + cfg = get_config() + u_min, v_min, u_max, v_max = bbox try: with sw.step("pointcloud_roi"): pc, _meta = nuwa.pointcloud_roi( @@ -81,11 +98,10 @@ def _object_points_in_base(conf: float | None, class_name: str | None, sw: Stopw cropped = filter_outliers(pc) if len(cropped) < 10: raise HTTPException(status_code=422, detail=f"too few valid depth points in bbox: {len(cropped)}") - with sw.step("to_base_frame"): pts_cv = nuwa_to_cv_frame(cropped[:, :3]) pts_base = transform_points(T_base_cam, pts_cv) - return pts_base, {"detection": top, "T_base_camera": T_base_cam.tolist(), "n_points": len(pts_base)} + return pts_base @router.post("/plan")