From a282414c1d21f40671c54d06aa63127599fb6c0d Mon Sep 17 00:00:00 2001 From: Xenolphthalein <21215869+Xenolphthalein@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:10:05 +0100 Subject: [PATCH] fix: pico4-monado fits the colour room view's lens model only over the angles it shows, so the room no longer wobbles toward the edges The RGB camera's fisheye62 model was fitted to KB4 over rays out to the image's corners (80-90 degrees off axis, up to 12 px off), which the headset never shows; they pulled the fit off inside the view, where its error swung between 0.3 and 1.7 px (worst 2.0 px at 55 degrees) and the room wobbled as points crossed it. Fitted up to 70 degrees it grows smoothly to about 1 px at the view's edge. The room view logs the fit's error at its start. The head tracker's fits stay as they were. --- phoenix/pico4-monado/PKGBUILD | 14 +++++++------- phoenix/pico4-monado/pico4_passthrough.c | 6 +++++- phoenix/pico4-monado/pico4_passthrough.h | 2 ++ phoenix/pico4-monado/pico4_slam.c | 7 +++++-- phoenix/pico4-monado/pico4_tcam.c | 12 +++++++++--- phoenix/pico4-monado/pico4_tcam.h | 13 +++++++++++++ phoenix/pico4-monado/test_pico4_tracking.c | 22 ++++++++++++++++++++++ 7 files changed, 63 insertions(+), 13 deletions(-) diff --git a/phoenix/pico4-monado/PKGBUILD b/phoenix/pico4-monado/PKGBUILD index 22e0139..a1ea6f1 100644 --- a/phoenix/pico4-monado/PKGBUILD +++ b/phoenix/pico4-monado/PKGBUILD @@ -18,7 +18,7 @@ # overlays (Overpressure Settings' dashboard tab, the first-run setup). pkgname=pico4-monado pkgver=25.1.0 -pkgrel=17 +pkgrel=18 arch=(aarch64) url="https://monado.freedesktop.org" license=(BSL-1.0) @@ -83,10 +83,10 @@ sha256sums=(SKIP '732a6738b8e89063d247c820f0fdf6de7be2b2b9435e751886450474ffa7a2d0' '93a500075473c85d7c9d1ce81f609a26f876d18c8325b10af5e710c44657d7da' '41bb03af46edb3c3a593cefbc2246382826a16a3b567619b937d9f45df85eedb' - 'a82b964bb5e5437f20ea2e596c3c6e67281d2ed8459351cadd2ef89bd6522bbe' - '40ec271b33e28552556de71a2ab81219860ffcd1a1b920949d9b5ac2d405f374' - '50a119d180c7a970a5196ee2428cd8ce166cf8bb392e8fc90a5607ba7302c3ed' - '76ba6acb295abafd3235bf828bc3534543ea0c279a054d38c032b48dcab17f89' + '46147c0c7d2013e76e4168479651813f462a9ee89e0ba3606427576b24099443' + '723538607265c89266e50d5a301aabfcdf80b695088f0b73256364638bb83330' + 'c9aed4ebbe10c87232c89dbd3299072bf311e50ebdc33d0c474ae302106e1900' + 'ae0e6142841aba8f4bdccc40347f2669b06a10dabe7c4119ea074335b179ad11' '54aa815f0d7e4a1370b94cf1e51c3ce84c38d6bdad66d7e2a41e56ed598efbd8' 'e160944ec154fa5caf43d2177396656c8561d1739df07510ce75c3b8ddafa3b3' '8a4eb266bc10fb356f687f42f7d7eb67cdf84fb19a8183942f68ee2e7924fe9b' @@ -106,7 +106,7 @@ sha256sums=(SKIP 'b6e41fc4689a3fa4cd287a88a62d922aef5c5f26467f6edbe180c24ebdd71786' 'cc727edbad724f50656255313d81ebc56dc6c168bbe05f10f8c57cfecd3829a4' '1e216b8317b7dcbdefb623a59dedf67ab580ffcfcd5b671a5420e777ce88aea9' - '15458e31c35d4b5ea13b8bfdc342c03a45da727787a1ca2c1f9bafa551c7674a' + '58f7dba6fbdb8473b6efffd4a31ce4ce32fd485d499355802ca850923e0bcfd6' 'f45d76a543f622df7d8f67d7c8e541675832b80c1076afeed3499ecd06aba7f2' 'd573cc225562750c4003cab1c47ce52deddd58bc61a36f10c6d6f14086821f47' 'b229c53f03c67e4de8e30651f861deec6fd0140c8946d308402f00ca80cc356e' @@ -114,7 +114,7 @@ sha256sums=(SKIP 'a52d561a66f774bfab2183f626d1eca003e69e40d5b1ef98a5e8fc2b1e4c4377' '3b5723d2dfee9343828f49228ccaaf490205e2588bb02b39d5171b5d7299b619' '85c59e96fa7aff425f05c3129679c707a324de9ff7870d11b977e2439c2c6463' - '33a77a059c243a3113b9d93125958a3ab4a4cf34491818f06134725c5e4f0bd3' + '7e332686ec26c09e0a0162047f3ec99e09cfa8bd1428f7acc8699b5646c46b67' '4d65eeb635e98fb994fecf8cd5448e754c97c598eacea86852fb8930eaaadd08' '6f9e6b63f008118305f60253257bcbf28354594e84b7bd8fa3b5ca33dcd11872' '6168eaa35df0d363fbd7b5b86fca92b2aa63c2c06979932cf03a9531279773cc' diff --git a/phoenix/pico4-monado/pico4_passthrough.c b/phoenix/pico4-monado/pico4_passthrough.c index ed5aad3..5f79a8c 100644 --- a/phoenix/pico4-monado/pico4_passthrough.c +++ b/phoenix/pico4-monado/pico4_passthrough.c @@ -414,7 +414,9 @@ pico4_passthrough_use_rgb(struct pico4_passthrough *p, const char *calibration_d char *text = read_file(path); struct pico4_tcam_omni omni; struct pico4_tcam_kb4 kb4; - bool ok = text != NULL && pico4_tcam_parse_yaml(text, &omni) && pico4_tcam_fit_kb4(&omni, &kb4) && + // Fitted over the angles the room view shows only (PICO4_TCAM_ROOMVIEW_DEG). + bool ok = text != NULL && pico4_tcam_parse_yaml(text, &omni) && + pico4_tcam_fit_kb4_within(&omni, PICO4_TCAM_ROOMVIEW_DEG, &kb4) && omni.width == PICO4_PASSTHROUGH_RGB_SRC_W && omni.height == PICO4_PASSTHROUGH_RGB_SRC_H; free(text); if (!ok || p->exporting) { @@ -429,6 +431,8 @@ pico4_passthrough_use_rgb(struct pico4_passthrough *p, const char *calibration_d memset(i, 0, sizeof(*i)); i->width = PICO4_PASSTHROUGH_RGB_W; i->height = PICO4_PASSTHROUGH_RGB_H; + i->fit_rms_px = kb4.rms_px / 2; + i->fit_max_px = kb4.max_px / 2; for (int c = 0; c < PICO4_PASSTHROUGH_CAMS; c++) { // One pixel per 2x2 cell: cell x covers sensor columns 2x and 2x + 1, centred on 2x + 0.5. i->fx[c] = kb4.fx / 2; diff --git a/phoenix/pico4-monado/pico4_passthrough.h b/phoenix/pico4-monado/pico4_passthrough.h index 28177c5..897a66c 100644 --- a/phoenix/pico4-monado/pico4_passthrough.h +++ b/phoenix/pico4-monado/pico4_passthrough.h @@ -39,6 +39,8 @@ struct pico4_passthrough_info * HmdMatrix34_t, in OpenVR's camera axes (x right, y up, looking along -z). */ double camera_to_head[PICO4_PASSTHROUGH_CAMS][12]; + //! The RGB camera's KB4 fit against its factory model, in pixels of the image the room view gets. + double fit_rms_px, fit_max_px; }; //! One delivered frame. diff --git a/phoenix/pico4-monado/pico4_slam.c b/phoenix/pico4-monado/pico4_slam.c index 4b3d823..e1b2279 100644 --- a/phoenix/pico4-monado/pico4_slam.c +++ b/phoenix/pico4-monado/pico4_slam.c @@ -1555,8 +1555,11 @@ pico4_slam_create(const char *calibration_dir, struct pico4_passthrough_info info; pico4_passthrough_rgb_info(s->passthrough, &info); const double *m = info.camera_to_head[0]; - SLAM_INFO(s, "Room view from the RGB camera: %ux%u, at %.3f %.3f %.3f m, looking %.2f %.2f %.2f", - info.width, info.height, m[3], m[7], m[11], -m[2], -m[6], -m[10]); + SLAM_INFO(s, + "Room view from the RGB camera: %ux%u, at %.3f %.3f %.3f m, looking %.2f %.2f %.2f; " + "lens fit up to %.0f degrees: rms %.2f px, max %.2f px", + info.width, info.height, m[3], m[7], m[11], -m[2], -m[6], -m[10], PICO4_TCAM_ROOMVIEW_DEG, + info.fit_rms_px, info.fit_max_px); } else { SLAM_WARN(s, "No calibration of the RGB camera (cam4) in %s: the room view stays grey", calibration_dir); } diff --git a/phoenix/pico4-monado/pico4_tcam.c b/phoenix/pico4-monado/pico4_tcam.c index 54ff2a6..2bef566 100644 --- a/phoenix/pico4-monado/pico4_tcam.c +++ b/phoenix/pico4-monado/pico4_tcam.c @@ -156,7 +156,7 @@ struct sample * image and moves outwards (the radtan polynomial folds back far out). */ static int -make_samples(const struct pico4_tcam_omni *c, struct sample *s, int max) +make_samples(const struct pico4_tcam_omni *c, double max_theta, struct sample *s, int max) { const int azimuths = 72, steps = 120; int n = 0; @@ -164,7 +164,7 @@ make_samples(const struct pico4_tcam_omni *c, struct sample *s, int max) double phi = 2 * M_PI * a / azimuths; double last_r = -1; for (int i = 1; i <= steps && n < max; i++) { - double theta = (M_PI * 0.75) * i / steps; // up to 135 degrees off axis + double theta = max_theta * i / steps; double p[3] = {sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)}; double uv[2]; if (!pico4_tcam_omni_project(c, p, uv)) { @@ -251,13 +251,19 @@ solve(double a[NPARAM][NPARAM], double b[NPARAM], double x[NPARAM]) bool pico4_tcam_fit_kb4(const struct pico4_tcam_omni *c, struct pico4_tcam_kb4 *out) +{ + return pico4_tcam_fit_kb4_within(c, 135.0, out); // as far as the image reaches +} + +bool +pico4_tcam_fit_kb4_within(const struct pico4_tcam_omni *c, double max_deg, struct pico4_tcam_kb4 *out) { const int max = 72 * 120; struct sample *s = calloc(max, sizeof(*s)); if (s == NULL) { return false; } - int n = make_samples(c, s, max); + int n = make_samples(c, max_deg * M_PI / 180, s, max); // Near the axis the omni model scales tan-angles by f / (1 + xi). double x[NPARAM] = {c->fu / (1 + c->xi), c->fv / (1 + c->xi), 0, 0, 0, 0}; double lambda = 1e-3, f = cost(x, c->pu, c->pv, s, n); diff --git a/phoenix/pico4-monado/pico4_tcam.h b/phoenix/pico4-monado/pico4_tcam.h index c806202..dd6f94c 100644 --- a/phoenix/pico4-monado/pico4_tcam.h +++ b/phoenix/pico4-monado/pico4_tcam.h @@ -73,6 +73,19 @@ pico4_tcam_kb4_project(const struct pico4_tcam_kb4 *c, const double p[3], double bool pico4_tcam_fit_kb4(const struct pico4_tcam_omni *c, struct pico4_tcam_kb4 *out); +/*! + * The angle off the RGB camera's axis the room view shows, with a margin: the view's edge lies at about 55-60 + * degrees. Fitted only up to here, the corners the headset never shows (up to 12 px off at 80-90 degrees) no + * longer pull the fit off inside the view, where its error swung and made the room wobble toward the edges. + */ +#define PICO4_TCAM_ROOMVIEW_DEG 70.0 + +/*! + * Fit as pico4_tcam_fit_kb4() does, over the rays up to @p max_deg off the axis only. + */ +bool +pico4_tcam_fit_kb4_within(const struct pico4_tcam_omni *c, double max_deg, struct pico4_tcam_kb4 *out); + /*! * Describe the same camera with its image turned by 180 degrees (pixel (u, v) * read at (width - 1 - u, height - 1 - v)): the principal point moves and the diff --git a/phoenix/pico4-monado/test_pico4_tracking.c b/phoenix/pico4-monado/test_pico4_tracking.c index 37a928b..0c71df5 100644 --- a/phoenix/pico4-monado/test_pico4_tracking.c +++ b/phoenix/pico4-monado/test_pico4_tracking.c @@ -300,6 +300,28 @@ test_calibration(void) printf("RGB KB4 fit: rms %.3f px, max %.3f px over %d rays\n", rk.rms_px, rk.max_px, rk.samples); EXPECT(rk.samples > 1000); + // The room view's fit, over the angles it shows only: closer to the factory model wherever the view looks. + struct pico4_tcam_kb4 rv; + EXPECT(pico4_tcam_fit_kb4_within(&rgb, PICO4_TCAM_ROOMVIEW_DEG, &rv)); + EXPECT(rv.samples > 1000 && rv.cx == rgb.pu && rv.cy == rgb.pv); + double full_worst = 0, view_worst = 0; + for (int deg = 5; deg <= 60; deg += 5) { + for (int az = 0; az < 360; az += 10) { + double t = deg * M_PI / 180, f = az * M_PI / 180; + double ray[3] = {sin(t) * cos(f), sin(t) * sin(f), cos(t)}, want[2], got[2]; + if (!pico4_tcam_omni_project(&rgb, ray, want)) { + continue; + } + pico4_tcam_kb4_project(&rk, ray, got); + full_worst = fmax(full_worst, hypot(got[0] - want[0], got[1] - want[1])); + pico4_tcam_kb4_project(&rv, ray, got); + view_worst = fmax(view_worst, hypot(got[0] - want[0], got[1] - want[1])); + } + } + printf("RGB fit within 60 degrees: worst %.3f px fitted to %.0f degrees, %.3f px fitted to the corners\n", + view_worst, PICO4_TCAM_ROOMVIEW_DEG, full_worst); + EXPECT(view_worst < full_worst); + // A camera turned by 180 degrees sees a body point at the mirrored pixel. struct pico4_tcam_kb4 r = k; double T[16];