Spaces:
Running
Running
Commit
Β·
496b9fb
1
Parent(s):
31ccc32
WIP head bug fixing - logging
Browse files- reachy_phone_home/main.py +32 -16
reachy_phone_home/main.py
CHANGED
|
@@ -303,24 +303,36 @@ def _fix_camera_intrinsics(reachy: ReachyMini, logger: logging.Logger) -> None:
|
|
| 303 |
logger.warning("[camera_diag] resolution not set yet, skipping fix")
|
| 304 |
return
|
| 305 |
|
| 306 |
-
#
|
| 307 |
-
#
|
| 308 |
-
#
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
-
|
| 315 |
-
# (within 10 %), K is already appropriate β nothing to do.
|
| 316 |
-
if abs(cal_w - frame_w) / frame_w < 0.1 and abs(cal_h - frame_h) / frame_h < 0.1:
|
| 317 |
logger.info(
|
| 318 |
-
"[camera] K matrix
|
| 319 |
-
|
|
|
|
| 320 |
)
|
| 321 |
return
|
| 322 |
|
| 323 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
w_ratio = frame_w / cal_w
|
| 325 |
h_ratio = frame_h / cal_h
|
| 326 |
|
|
@@ -332,11 +344,15 @@ def _fix_camera_intrinsics(reachy: ReachyMini, logger: logging.Logger) -> None:
|
|
| 332 |
|
| 333 |
cam.resized_K = fixed_K
|
| 334 |
logger.info(
|
| 335 |
-
"[camera] Fixed K matrix for %dx%d frames
|
| 336 |
-
|
|
|
|
| 337 |
)
|
| 338 |
-
logger.info("[camera] Original K:\n%s", orig_K)
|
|
|
|
| 339 |
logger.info("[camera] Corrected K:\n%s", fixed_K)
|
|
|
|
|
|
|
| 340 |
|
| 341 |
|
| 342 |
def run_tracker(
|
|
|
|
| 303 |
logger.warning("[camera_diag] resolution not set yet, skipping fix")
|
| 304 |
return
|
| 305 |
|
| 306 |
+
# Check BOTH the active resized_K and the original specs.K for mismatches.
|
| 307 |
+
# The active K's principal point should be near the centre of the frame.
|
| 308 |
+
# If either is off by more than 10%, we need to fix.
|
| 309 |
+
active_cx = current_K[0, 2]
|
| 310 |
+
active_cy = current_K[1, 2]
|
| 311 |
+
expected_cx = frame_w / 2.0
|
| 312 |
+
expected_cy = frame_h / 2.0
|
| 313 |
+
|
| 314 |
+
active_ok = (
|
| 315 |
+
abs(active_cx - expected_cx) / expected_cx < 0.1
|
| 316 |
+
and abs(active_cy - expected_cy) / expected_cy < 0.1
|
| 317 |
+
)
|
| 318 |
|
| 319 |
+
if active_ok:
|
|
|
|
|
|
|
| 320 |
logger.info(
|
| 321 |
+
"[camera] K matrix looks correct for %dx%d frames "
|
| 322 |
+
"(cx=%.1f, cy=%.1f vs expected ~%.0f, ~%.0f) β no correction needed",
|
| 323 |
+
frame_w, frame_h, active_cx, active_cy, expected_cx, expected_cy,
|
| 324 |
)
|
| 325 |
return
|
| 326 |
|
| 327 |
+
# The active K is wrong. Recompute from specs.K, which should be
|
| 328 |
+
# calibrated for a resolution whose centre matches (specs.K cx, cy).
|
| 329 |
+
orig_K = specs.K
|
| 330 |
+
orig_cx = orig_K[0, 2]
|
| 331 |
+
orig_cy = orig_K[1, 2]
|
| 332 |
+
cal_w = orig_cx * 2 # approximate calibration width
|
| 333 |
+
cal_h = orig_cy * 2 # approximate calibration height
|
| 334 |
+
|
| 335 |
+
# Rescale from the calibration resolution to the actual frame resolution.
|
| 336 |
w_ratio = frame_w / cal_w
|
| 337 |
h_ratio = frame_h / cal_h
|
| 338 |
|
|
|
|
| 344 |
|
| 345 |
cam.resized_K = fixed_K
|
| 346 |
logger.info(
|
| 347 |
+
"[camera] Fixed K matrix for %dx%d frames "
|
| 348 |
+
"(active cx,cy was %.1f,%.1f β expected ~%.0f,%.0f)",
|
| 349 |
+
frame_w, frame_h, active_cx, active_cy, expected_cx, expected_cy,
|
| 350 |
)
|
| 351 |
+
logger.info("[camera] Original specs.K:\n%s", orig_K)
|
| 352 |
+
logger.info("[camera] Broken resized_K:\n%s", current_K)
|
| 353 |
logger.info("[camera] Corrected K:\n%s", fixed_K)
|
| 354 |
+
WEB_UI.append_log(f"[camera] Fixed K: cx {active_cx:.1f}β{fixed_K[0,2]:.1f}, "
|
| 355 |
+
f"cy {active_cy:.1f}β{fixed_K[1,2]:.1f}")
|
| 356 |
|
| 357 |
|
| 358 |
def run_tracker(
|