Repository navigation
egocap: calibration library, command line, and a launcher that starts the bridge with a rectification table - #1635
Conversation
…t launch Add the station-side calibration code of the Ego Capture example: a library under recording/egocap/calibration, a command line (recording/tools/calibrate_station.py), and a launcher that starts the camera bridge with a rectification table. Camera calibration - Lens calibration from a ChArUco board take under a pinhole or a fisheye model, graded excellent, acceptable or bad; the grade decides what may be installed. - The head camera's position on the headset (hand-eye), with a search for the camera's lag against tracking. - Head tracking that fails during the take is told from the head track: where the position stops following the head's turning its samples are left out, and where the position leaps the take is split and the longest sound stretch is solved. The record and the log state what the take read. - A live guide a caller feeds pictures and head poses: views, coverage, head motion and head-tracking health, each with what it asks for. Controller-to-glove offsets - The least-squares fit and the projection a labelling tool draws. Rectification - A planner with explicit geometry: output size, balance, field-of-view scale or a stated output camera matrix, and optional oversampling. A plan that would leave pixels without a source is refused unless borders are allowed. - It writes the remap table the bridge's rectify step loads, and an offline rectified copy of a take. - tools/start_system.py reads the station's plan, writes a table per planned stream, starts the bridge with it and records what it applied. --no-rectify starts without correction. Station files - One home for file names and readers; installs are atomic, archive what they replace and are logged with who installed them. In a session recorded with correction each camera's intrinsics file describes the recorded picture, and the lens calibration is kept beside it. Aligner - Camera times are moved by the lag calibration measured before aligning, and the aligned episode records what was taken off. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Shawn Hwang <shhwang@nvidia.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
🤖 Agent-generated (Claude Code · claude-sonnet-5-5) @NVshawnhwang the controller-to-glove offset in this stack overlaps with #1625 (@Yunjuliii), which also adds a controller-to-Manus-wrist offset calibration. They reach the same kind of result by different routes, and the two should be compared before both land. Could you break the controller-to-glove offset out into its own pull request or short stack, independent of the rest of the calibration work? It currently spreads over:
The per-operator glove calibration files in #1640 are the SDK's own glove calibration and are a separate feature, so they do not need to move. Yunju is being asked to split #1625 the same way, so that the sensor recording and the offset solvers are separate. We will compare the two offset implementations (output format, convention, where the result is stored and read, how it is run) and agree one design before either merges. Yunju is now a reviewer on #1635, #1636 and #1637, and you are a reviewer on #1625. |
|
🤖 Agent-generated (Claude Code · claude-sonnet-5-5) Summary This adds the station calibration library (lens intrinsics, head-camera hand-eye, grading, live guide, controller-to-glove offsets, rectification planner, station store), the Legend: 🚫 Blocker · 💡 Suggestion · 🔍 Nit
Verified without finding
Questions for Shawn
Actionables (for bots — copy-paste-ready for AI)
|
…gocap_calibration_library Signed-off-by: Shawn Hwang <shhwang@nvidia.com>
NVdejung
left a comment
There was a problem hiding this comment.
🤖 Automated first-pass review (Claude, for Dejun) — I'll follow up personally where needed.
Summary — Adds the station calibration library (ChArUco intrinsics under pinhole or fisheye, head-camera hand-eye with a lag search and tracking-loss handling, grading, a live guide, glove offsets, the rectification planner and remap tables, the station store), a calibrate_station.py command line, per-stream rectification in the launcher, and camera-lag subtraction in the aligner. The library is careful and very thoroughly tested. The blocking problem is where the pieces join: at this head the launcher can correct video that the backend does not yet record as corrected.
Must fix
-
tools/start_system.py:1091— Rectification is applied but not recorded. The launcher corrects every stream whose rolerectification/plan.jsonswitches on. Nothing at this head records that in the session:- the backend still copies only the five station files (
backend/egocap_web/app.py:166); - nothing reads
EGOCAP_STREAMS_STATE.
So a corrected session gets the lens intrinsics as
head_camera_intrinsics.json, with no lens file and norectification.json. This PR's ownrecorded_rectification()then reads those takes as recorded as received.calibrate_station.py camerawould solve a lens from corrected video, andrectifywould correct it a second time. That is the silent, irreversible case the library exists to refuse.The README (
:87,:196) and the PR description both state the backend behaviour as fact. Nothing in this PR writes a plan, so the problem is latent for now. It goes live once any PR that saves a plan (likely#1636) reachesmainahead of the backend change that records it.Fix: land the backend's session assets with or before the first PR that can write a plan, or have the launcher refuse an enabled plan until then. Either way, make the README describe this head. If the whole stack lands on
mainas one unit, say so in the description and this shrinks to the README fix. - the backend still copies only the five station files (
Suggestions
recording/tools/calibrate_station.py:675—camera --installwrites intrinsics stamped only withcameraandcalibrated_at(camera_pipeline.py:852), with nostreamdivisor. A lens solved on the default half-size stream is therefore refused by the launcher's planner (rectify.py:354);test_start_system.py:1443pins exactly that. Givecameraa divisor/source-size option, astablehas--calibration-divisor, or say in its help that its output cannot drive a plan.recording/README.md:53— four links to../CALIBRATION_TOOLS.md, which is not in this PR. Operator messages also name tools that arrive later: "the Rectification tool" (start_system.py:134,grading.py:310) and "the Headset calibration tool" (calibrate_station.py:10).calibration/files.py:273— any file withoutpose_sourceis reported as "made with another tracking source or another tool". On existing stations this prints at every launch, and the aligner drops their lag; the discussion found the existing offsets numerically compatible. Reword it to "does not state its pose source", and check which installed files are affected.calibration/hand_view.py:52—scale_Kscales cx/cy without the (s−1)/2 pixel-centre term thatrectify._before_box_filterapplies: 0.25 px off at a 2× downscale. It also accepts any scale that keeps the aspect ratio, while the planner accepts only an exact integer divisor. The error is small, but it feeds the wrist-offset fit; one shared helper would keep the two rules in step.recording/aligned_writer.py:40—egocap.recordingnow importsegocap.calibration(board, take, camera_lag), andegocap.calibrationalready importsegocap.recording. That makes a two-way package dependency, and it brings the ChArUco and take readers into the aligner for one exception class and one constant. Moving those (or the lag rule) into a small module would keep the dependency one-way.
Not repeated here, and still open in the discussion: the aligned-episode format point, the one-lag-for-every-camera assumption, install limits tried only on synthetic data, the PR's size, and the request to split out the glove offset.
Conflicts
- With
nvShawnHwang/egocap_rectify_bridge(#1634's branch): no conflicts in the 3-way merge, 0 commits behind, no rebase needed. The launcher's--stream NAME=TRACK:DIVand--gpu-step NAME:rectify=PATHarguments and the 48-byteICRMAP01table header match#1634's parser and reader. - Stack children
#1636–#1646(same author): no textual conflicts.#1646replaces this PR's one-stream launcher wiring. #1606(Yunjuliii, draft, based onmain) — semantic conflict: it adds a three-camera rig tostart_system.py, while this PR assumes one bridged stream (:1081; theegodefault instream_rolesapplies only when there is one stream). Agree with#1646which design wins before either lands.#1625(Yunjuliii, draft) — semantic conflict: it also editsalignment.py, where this PR addscamera_lag_stoalign_episode, and it has its own controller-to-wrist offset. The comparison asked for in the discussion is still open.#1566,#1571,#1586,#1670(gareth-morgan-nv) and#1587(fvaloppi-nv) touch the same launcher, test or README files from other bases, so conflicts were not computed. The likely clash is the bridge-start block (start_system.py:1244). For#1571, note that the launcher now importsegocap.calibrationwhen it loads, so it must run in the egocap environment. Whichever lands second rebases; expect this stack to rebase when#1634retargetsmain.
Not verified: I ran no tests (no shell here). intrinsics.py, extrinsics.py, guidance.py and the roughly 20k lines of tests were skimmed, not read line by line.
Change-by-change (49 files)
| File / area | What changed | Makes sense? |
|---|---|---|
recording/README.md |
Documents the calibration package, corrected sessions, lens files in the session tree, camera-lag alignment | CALIBRATION_TOOLS.md not in this PR (must-fix 1, suggestion 2) |
calibration/__init__.py |
Package docstring | ✅ |
calibration/board.py |
ChArUco spec validation, detector that settles on the legacy or current layout, sharpness measure | ✅ |
calibration/camera_model.py |
Projection and inversion per lens model, field limit, board pose | ✅ |
calibration/frames.py |
OpenXR ↔ forward-left-up helpers | ✅ |
calibration/files.py |
File names, role maps, atomic JSON write, intrinsics reader, camera-stamp and pose-source checks | ✅ (wording, suggestion 3) |
calibration/take.py |
Read-only episode reader: frames, poses, tracking latency | ✅ |
calibration/intrinsics.py |
Pinhole/fisheye solve with outlier rounds and evidence keys | ✅ skimmed |
calibration/extrinsics.py |
Hand-eye solve, head-track loss and leap detection, lag search | ✅ skimmed; the maths was checked numerically in the discussion |
calibration/grading.py |
Grades and install gates | ✅ intrinsics gate agrees with the planner's 0.5 px limit |
calibration/guidance.py |
Live guide for recording a take | ❓ no caller until the page PRs (skimmed) |
calibration/camera_pipeline.py |
Pick frames, solve, grade; review folder kept out of the session | ✅ (no stream stamp, suggestion 1) |
calibration/camera_lag.py |
One rule for applying a stored lag | ✅ |
calibration/wrist_offset.py, hand_view.py |
Controller-to-glove fit, frame picking, overlay | ❓ split requested in the discussion; no caller here (suggestion 4) |
calibration/rectify.py |
Explicit-geometry planner, gates, preview, table writer and reader, vectorised FNV-1a | ✅ header matches #1634's reader |
calibration/rectification_files.py |
Plan file, streams state, a take's rectification record | write_plan and read_streams_state have no production caller at this head (must-fix 1) |
calibration/rectify_take.py |
Offline corrected copy | ✅ output refused inside or around the session; staged, then renamed into place |
calibration/station_store.py |
Locked atomic install, archive, ledger | ✅ |
recording/aligned_writer.py, alignment.py, tools/align_episode.py |
Subtract a stated camera lag, camera_lag attribute, lens files as sidecars |
✅ no-op without a stated lag (suggestion 5) |
recording/tools/calibrate_station.py |
camera, rectify, table subcommands |
|
tools/start_system.py |
Plan → tables → --gpu-step; streams state; --stream-role, --no-rectify; pose-source warnings; table cleanup |
|
Tests: 3 helpers + 20 tests/recording/unit/test_*, tests/tools/test_calibrate_station.py, test_start_system.py |
Synthetic-data coverage of all of the above; launcher tests isolate the calibration directory | ✅ skimmed, not run |
Reviewed at 3135505 · 49 files · 2026-12-01 12:52 PST
Summary
Second of four stacked pull requests (on top of the bridge's
rectifystep). It adds the station-sidecalibration code for the Ego Capture example, with no page and no backend routes yet:
recording/egocap/calibration/;recording/tools/calibrate_station.py;tools/start_system.py) builds each camera's remap table from the station's plan at start andstarts the camera bridge with it;
What it does
Camera calibration (
camerasubcommand;camera_pipeline.py,intrinsics.py,extrinsics.py,grading.py,guidance.py,board.py,take.py)fisheye model), with outlier passes and a grade (excellent, acceptable, bad) that decides what may be installed.
following the head's turning the samples are left out, and where the position leaps the take is split and the
longest sound stretch is solved. The record and the log state what the take read.
guidance.py) that a caller feeds pictures and head poses: views, coverage, head motion andhead-tracking health, each with the amount it asks for.
Controller-to-glove offsets (
wrist_offset.py,hand_view.py): the least-squares fit and the projectionthe labelling tool draws.
Rectification (
rectify.py,rectify_take.py,rectification_files.py;rectifyandtablesubcommands)optional oversampling. No automatic crop search and no silent fallback: a plan that would leave pixels without
a source is refused unless borders are allowed.
rectifystep loads, and an offline rectified copy of a take.<calibration dir>/rectification/plan.json, writes one table per planned stream, startsthe bridge with
--gpu-step <stream>:rectify=<table>, and records what it applied instreams_state.json.--no-rectifystarts without correction.Station files (
files.py,station_store.py): one home for file names and readers, atomic installs with anarchive of what was replaced and a ledger of who installed what. In a session recorded with correction, each
camera's intrinsics file describes the recorded (corrected) picture and the lens calibration is kept beside it
under its own name.
Aligner (
camera_lag.py,alignment.py,aligned_writer.py): camera times are moved by the measured lagbefore aligning, and the aligned episode records what was taken off.
How it was tested
tests/recordingat 100% line and branch coverage forrecording/egocap(the tree's gate),tests/tools.bridge's C++ reader; the bridge's host reference produced byte-identical output to an independent NumPy
implementation on planner-written tables.
alone is found in every take; a sound take that reads low loses frames, not its grade.
Not yet verified on hardware
The solve logs the take's lowest and median reading (millimetres of position per degree of turning), so the
first real take shows whether a sound sweep reads above the limit here.
🤖 Generated with Claude Code