Spaces:
Building
on
A10G
Building
on
A10G
Zhen Ye
commited on
Commit
·
61fbbca
1
Parent(s):
fc53373
fix:distance consistency
Browse files- LaserPerception/LaserPerception.js +17 -1
- inference.py +14 -1
LaserPerception/LaserPerception.js
CHANGED
|
@@ -2644,10 +2644,26 @@
|
|
| 2644 |
|
| 2645 |
tr.label = best.label || tr.label;
|
| 2646 |
tr.score = best.score || tr.score;
|
|
|
|
|
|
|
| 2647 |
if (best.depth_valid && Number.isFinite(best.depth_est_m)) {
|
| 2648 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2649 |
tr.depth_rel = Number.isFinite(best.depth_rel) ? best.depth_rel : tr.depth_rel;
|
| 2650 |
tr.depth_valid = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2651 |
}
|
| 2652 |
tr.lastSeen = now();
|
| 2653 |
}
|
|
|
|
| 2644 |
|
| 2645 |
tr.label = best.label || tr.label;
|
| 2646 |
tr.score = best.score || tr.score;
|
| 2647 |
+
|
| 2648 |
+
// Depth smoothing with hysteresis
|
| 2649 |
if (best.depth_valid && Number.isFinite(best.depth_est_m)) {
|
| 2650 |
+
// EMA smoothing
|
| 2651 |
+
if (tr.depth_est_m == null) {
|
| 2652 |
+
tr.depth_est_m = best.depth_est_m;
|
| 2653 |
+
} else {
|
| 2654 |
+
tr.depth_est_m = lerp(tr.depth_est_m, best.depth_est_m, 0.35);
|
| 2655 |
+
}
|
| 2656 |
tr.depth_rel = Number.isFinite(best.depth_rel) ? best.depth_rel : tr.depth_rel;
|
| 2657 |
tr.depth_valid = true;
|
| 2658 |
+
tr.lastDepthTime = now();
|
| 2659 |
+
} else {
|
| 2660 |
+
// Hysteresis: hold last valid depth for 0.8s
|
| 2661 |
+
if (tr.lastDepthTime && (now() - tr.lastDepthTime) < 800) {
|
| 2662 |
+
// keep existing tr.depth_est_m
|
| 2663 |
+
} else {
|
| 2664 |
+
tr.depth_valid = false;
|
| 2665 |
+
tr.depth_est_m = null; // fallback to area
|
| 2666 |
+
}
|
| 2667 |
}
|
| 2668 |
tr.lastSeen = now();
|
| 2669 |
}
|
inference.py
CHANGED
|
@@ -246,7 +246,20 @@ def _attach_depth_metrics(
|
|
| 246 |
y2 = max(y1 + 1, min(height, y2))
|
| 247 |
|
| 248 |
patch = depth_map[y1:y2, x1:x2]
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
if finite.size == 0:
|
| 251 |
continue
|
| 252 |
|
|
|
|
| 246 |
y2 = max(y1 + 1, min(height, y2))
|
| 247 |
|
| 248 |
patch = depth_map[y1:y2, x1:x2]
|
| 249 |
+
if patch.size == 0:
|
| 250 |
+
continue
|
| 251 |
+
|
| 252 |
+
# Center crop (50%) to avoid background
|
| 253 |
+
h_p, w_p = patch.shape
|
| 254 |
+
cy, cx = h_p // 2, w_p // 2
|
| 255 |
+
dy, dx = h_p // 4, w_p // 4
|
| 256 |
+
center_patch = patch[cy - dy : cy + dy, cx - dx : cx + dx]
|
| 257 |
+
|
| 258 |
+
# Fallback to full patch if center is empty (unlikely)
|
| 259 |
+
if center_patch.size == 0:
|
| 260 |
+
center_patch = patch
|
| 261 |
+
|
| 262 |
+
finite = center_patch[np.isfinite(center_patch)]
|
| 263 |
if finite.size == 0:
|
| 264 |
continue
|
| 265 |
|