garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/camera-tracking.md

raw


topic: camera tracking (visual-inertial odometry) triggers: [cartopolis_vio, "crates/vio", vio, odometry.rs, attitude.rs, scale.rs, "image.rs", sim.rs, precise_tracker, Tracker, Anchor, "Lucas-Kanade", "Lucas–Kanade", FAST, "visual-inertial", "gyro bias", "camera tracking", HAND_HEIGHT_M] updated: 2026-10-17

Camera tracking

How the high-precision mode follows the phone in a hand to the centimetre (crates/vio, cartopolis_vio; run by systems::precise_tracker). The mode around it — the switch, the sensors, the log — is high-precision-mode.md; what uses the hand is hands-and-tones.md.

In plain terms

The camera is the eyes and the motion sensors the inner ear; neither is good enough alone.

  1. Landmarks. Thirty times a second the camera takes a small greyscale picture and picks out ~150 sharp details: window corners, brick joints, the edge of a sign.
  2. Following them. In the next picture it finds the same details again. Move the phone right and they slide left; move closer and they spread apart; near ones shift more than far ones — which is how distance is judged.
  3. The gyroscope says how it turned, very accurately. With the turning known, whatever the landmarks still did must be the phone moving.
  4. The accelerometer says how big the move was. A camera alone cannot tell a small step past a near wall from a big step past a far one; the accelerometer feels every push and stop, and comparing the two over a few seconds gives real centimetres.
  5. On the map once. At the lock it takes one GNSS fix and the compass heading and pins the tracking there. That is metres off, and for a virtual theremin nobody can see it does not matter: what matters is the hand moving steadily relative to it.

To use it: switch it on and hold the phone still a moment (it learns which way is down and how its gyroscope drifts), move it a little (the landmarks need parallax, the scale needs motion), and it says locked.

The pipeline

Frames. Device: Android's sensor axes (x right, y up, z out of the screen, portrait). Camera: the raw image (x right, y down, z along the lens). World: z up, heading wherever the phone pointed at the start. The back camera's mounting comes from SENSOR_ORIENTATION alone (Camera::back: a half turn about x, then a quarter turn about device z per 90°); LENS_POSE_* is ignored because the one phone measured reports it relative to itself.

Measured

The bench is why cartopolis_vio is Bevy-free, for the reason cartopolis_geo is: the tracker is developed and tested off the phone, against synthetic frames and motion with a known answer, and none of that should wait on the client's link.

On the bench, 2026-10-08 (crates/vio/src/sim.rs): points on a façade 6 m ahead, a pavement and a side wall; the phone held upright at 1.4 m, still for a second, then swaying ±25/12/10 cm with the wrist turning ±6–10°. Motion readings at 240 Hz derived from the path, frames at 30 Hz.

CaseError
Perfect sensors, corners projected exactlyworst 1.2 cm
Gyro bias 0.002 rad/s, accel bias 0.04 m/s², noise, 0.5 px corner noisemedian 6.6 mm, 95th 11.7 mm
As above, through rendered 640×480 frames and the whole image pipelinemedian 4.9 mm, 95th 9.9 mm

Error is measured after aligning the tracker's world to the truth at the first tracked frame (it has its own heading and origin). The rendered case took 3.1 s in the suite on 2026-10-27 (a Mac node), and 1.7 s once sim::render drew its rows on threads; the drawing is most of it.

From the first phone log (OnePlus 15, 2026-10-07): intrinsics reported (2795 px on a 4096×3072 array: ~437 px, ~72° across at 640×480), no distortion, LENS_POSE_REFERENCE 0, sensor orientation 90°, timestamps REALTIME — the camera and the gyroscope share a clock. Frames arrive 80–107 ms after they were taken; the camera ran at 30 fps and the motion sensors at ~240 Hz with a steady 4 ms gap.

What the bench taught

Each is a constant in the code with this beside it:

Not done, and what lost