Deploy backend
Browse files- pipeline.py +10 -5
pipeline.py
CHANGED
|
@@ -267,12 +267,17 @@ def sonar(image: Image.Image, mode: str, warning: str = "normal") -> dict:
|
|
| 267 |
return _sonar_result(depth_map(image, mode), warn_distance(mode, warning))
|
| 268 |
|
| 269 |
|
| 270 |
-
def _sonar_result(depth: np.ndarray, warn_m: float, mask: np.ndarray | None = None) -> dict:
|
|
|
|
| 271 |
hit = find_obstacle(depth, warn_m, mask)
|
| 272 |
if hit is None:
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
|
| 278 |
# Find mode. Spoken name -> DETR label. Only things DETR reliably detects; its label list also has
|
|
@@ -600,7 +605,7 @@ def find(
|
|
| 600 |
# detour ("something close on your left") just before arriving. A box on the floor in front of
|
| 601 |
# it still counts. Both distances come from this depth map, so its overreading up close cancels.
|
| 602 |
mask &= depth < target_distance - FIND_SELF_M
|
| 603 |
-
obstacle = _sonar_result(depth, warn_m, mask)
|
| 604 |
obstacle["low"] = low_obstacle(depth, mask, warn_m)
|
| 605 |
result["obstacle"] = obstacle
|
| 606 |
return result
|
|
|
|
| 267 |
return _sonar_result(depth_map(image, mode), warn_distance(mode, warning))
|
| 268 |
|
| 269 |
|
| 270 |
+
def _sonar_result(depth: np.ndarray, warn_m: float, mask: np.ndarray | None = None, with_box: bool = False) -> dict:
|
| 271 |
+
"""The /sonar fields; with_box adds `box` (Find uses it to tell when a detour has passed the obstacle)."""
|
| 272 |
hit = find_obstacle(depth, warn_m, mask)
|
| 273 |
if hit is None:
|
| 274 |
+
result = {"clear": True, "distance_m": None, "direction": None, "open": None}
|
| 275 |
+
else:
|
| 276 |
+
# Finer than half meters so the guide's thresholds change smoothly as you walk.
|
| 277 |
+
result = {"clear": False, "distance_m": round(hit["distance"], 1), "direction": hit["direction"], "open": hit["open"]}
|
| 278 |
+
if with_box:
|
| 279 |
+
result["box"] = hit["box"] if hit else None
|
| 280 |
+
return result
|
| 281 |
|
| 282 |
|
| 283 |
# Find mode. Spoken name -> DETR label. Only things DETR reliably detects; its label list also has
|
|
|
|
| 605 |
# detour ("something close on your left") just before arriving. A box on the floor in front of
|
| 606 |
# it still counts. Both distances come from this depth map, so its overreading up close cancels.
|
| 607 |
mask &= depth < target_distance - FIND_SELF_M
|
| 608 |
+
obstacle = _sonar_result(depth, warn_m, mask, with_box=True)
|
| 609 |
obstacle["low"] = low_obstacle(depth, mask, warn_m)
|
| 610 |
result["obstacle"] = obstacle
|
| 611 |
return result
|