Visual-Inertial Odometry

A camera sees the shape of a path but not its size. An IMU knows metres but drifts. On this toy walk the IMU alone is 32.7 m off after 30 s, and the camera alone draws the path 1.8 times too small. Fused, the scale estimate locks onto 1.8 within 8 s, and from then on the error stays near 4 cm.

Pick a navigator and set how long the camera stares at a blank wall. Watch who stays on the path. Then we build it piece by piece, from one pixel to a sliding window.

You need the Kalman filter and strapdown navigation. We build the rest from zero.

Lesson 16 of 22 in Sensor Fusion: Classical to Modern. It follows Calibration and Time Sync and leads to LiDAR-Inertial Factor Graphs.

Walk a figure eight

4 s

Illustrative planar toy: a 30 s figure eight, 6 m by 3 m. IMU at 100 Hz with accel bias (0.06, −0.04) m/s²; the toy knows the attitude. The camera returns positions at 10 Hz divided by the true scale 1.8, with 0.01 visual units (1.8 cm) of noise. The fused filter is a 7-state EKF that starts with scale 1.0. The blank wall starts at 14 s.

Chapter 0

One Camera Cannot See Size

Grow the whole world and watch every pixel stay where it was

You wear a VR headset indoors. There is no GPS and no base station, yet the virtual room stays still when you lean. The headset uses two cheap sensors: a camera and an IMU. This lesson is how they work together, a method called visual-inertial odometry (VIO): estimating your own motion from images and inertia.

Each sensor alone fails. Lesson 13 showed the IMU: its position error grows with time squared, so a 0.01 m/s² accelerometer bias is 18 m off after 60 s. The camera tracks image features, small patches it can find again in the next frame. While the same features stay in view, its error grows slowly. But it runs at about 30 frames a second, goes blind on a blank wall, and smears in a fast turn.

Its deepest gap is size. A camera divides by depth, so a world twice as big and twice as far makes the same picture.

Scale the world

Left, a side view: the camera (blue) and three landmarks (yellow). Right, the image the camera sees. Drag the world scale and watch the image.

1.00×

Illustrative pinhole, exact geometry: focal length 500 px, no lens distortion. The landmarks sit 0.4 m, 0.1 m and −0.3 m off the axis at depths 2.0 m, 2.6 m and 3.2 m. The scale multiplies all of them.

Call the focal length of the lens f, in pixels. Call a point's sideways offset from the lens axis X and its depth along the axis Z, both in metres. The pixel column where it lands is u.

Say it aloud

u equals f times X over Z.

u
u the pixel column, measured from the image centre.
f
f the focal length in pixels: 500 here.
X
X the point's sideways offset from the lens axis, in metres.
Z
Z the point's depth along the lens axis, in metres.
In plain words

Divide the offset X by the depth Z. Multiply by f. The result is the pixel u. Only the ratio of X to Z survives, so their size cancels.

With numbers

A point 0.4 m right and 2.0 m ahead: u = 500 × 0.4 / 2.0 = 100 px. Double both, to 0.8 m and 4.0 m: u = 500 × 0.8 / 4.0 = 100 px again.

So a single moving camera recovers the shape of its path but not its size. That is monocular scale ambiguity. The IMU fixes it. An accelerometer reads metres per second squared, a unit with metres in it, and gravity gives it a known 9.81 m/s² to stand on.

PropertyIMUOne camera
Rate200 to 1000 Hz20 to 60 Hz
Driftfast: error grows with t²slow while features stay in view
Metric sizeyesno
Dark, blank wall, blurunaffectedfails
Fast rotationthe gyro measures itfeatures leave the frame
The idea of the lesson. The camera gives a shape that barely drifts. The IMU gives metres and carries you through the gaps. Fuse them and you get the path at its true size.
Failure: monocular visual odometry alone. Symptom: the path has the right turns but the wrong length, and the error changes from run to run. Measure: walk a taped 1 m line and read the estimate. Fix: add an IMU (or a second camera) so a sensor in metres sets the size.

The road

  1. Scale from acceleration: three camera positions and one accelerometer reading.
  2. The reprojection residual: score the camera in pixels.
  3. One cost, two machines: loose or tight, filter or window.
  4. The MSCKF: use a landmark, then project it away.
  5. Marginalisation: forget a pose but keep what it taught.
  6. Preintegration: integrate the IMU once per keyframe.
  7. Observability: four things VIO can never know, and how to start.
  8. Showcase: run the whole filter on the figure eight.
  9. Read the symptom: blank walls, pure rotation, rolling shutter.
  10. Field guide: the numbers, the checklist, the code.
Why can one moving camera not tell how big the world is?

Chapter 1

Scale Lives in the Acceleration

Recover the metres per visual unit from three camera positions and one accelerometer reading

Visual odometry returns positions in visual units: the right shape, in a unit nobody chose. Call the number of metres in one visual unit λ, the scale. Every true position is λ times the visual one.

Try constant velocity first. The rig moves the same distance each second, and the camera sees the same number of visual units each second. Any λ fits, with a matching speed. The IMU does not help: at constant velocity it reads zero, which is true at every scale.

Acceleration breaks the tie. Take three camera positions one time step apart. Their second difference, the last minus twice the middle plus the first, is the acceleration times the step squared. In metres the accelerometer gives that number directly. In visual units the camera gives it too. Their ratio is λ.

Call the three visual positions s0, s1 and s2, the time between them Δt, and the accelerometer reading, after removing gravity, a.

Say it aloud

Lambda equals a times delta-t squared, over s-two minus two s-one plus s-zero.

λ
lambda the scale: metres per visual unit.
a
a the acceleration the IMU measured, gravity removed, in m/s².
Δt2
delta-t squared the time between camera positions, squared, in s².
s2 − 2s1 + s0
s-two minus two s-one plus s-zero the second difference of the visual positions, in visual units.
In plain words

Multiply the measured acceleration a by delta-t squared. That is how far the motion bent, in metres. Divide by how far it bent in visual units, the second difference of s. The quotient is lambda.

With numbers

With made-up numbers: speed 1.6 m/s, a = 0.4 m/s², Δt = 1 s, true λ = 1.8. The true positions are 0, 1.8 and 4.0 m, so the camera reads 0, 1.000 and 2.222. The second difference is 0.222. λ = 0.4 / 0.222 = 1.8. The speed follows too: 1.8 × 1.000 − 0.2 = 1.6 m/s.

Starve it of acceleration

Each dot is one 2 s window: three noisy camera positions and one accelerometer reading give one λ. The dashed line is the truth, 1.8. Slide the acceleration toward zero.

0.40 m/s²

Illustrative, seeded. Camera noise 0.01 visual units (1.8 cm) on each position, a perfect accelerometer, Δt = 1 s. The second difference then has noise √6 × 0.01. So the spread of λ is √6 × 0.01 × 1.8² / a: 11% at 0.4 m/s², 88% at 0.05.

The slider shows the rule. The camera's noise is fixed, so the signal must be large: the spread of λ falls as one over a. At 0.4 m/s² one window lands within about 11%. At 0.05 m/s² it is a guess. Real systems average many windows, and the filter of Chapter 8 does it at every frame.

Failure: a long, steady cruise. Symptom: a drone holds scale during take-off, then slowly mis-sizes everything in level flight. Measure: the acceleration over the last few seconds. Fix: add small manoeuvres, or a sensor in metres (stereo, a range sensor, wheel odometry).
The rig moves at a constant 1.6 m/s. What can the camera and IMU say about the scale?

Chapter 2

Score the Camera in Pixels

Predict where a landmark should land, and measure the gap to where it did

A camera does not measure position or depth. It measures where points land in the image. Detect a few hundred features per frame and match them to the next frame. One feature followed over many frames is a feature track: one 3-D point, the landmark, seen from many places. VNAV 6 builds the tracker.

To use a track, predict it. Take a guess of the camera pose and a guess of the landmark. Move the landmark into the camera's frame and project it. Compare the predicted pixel with the measured one.

Call the measured pixel z. Call the camera's rotation R and its position p, together the pose. Call the landmark's position ℓ and the pinhole projection of Chapter 0 π.

Say it aloud

r equals z minus pi of R-transpose times, ell minus p.

r
r the reprojection residual: two numbers, the gap in pixels across and down.
z
z the pixel where the tracker found the feature.
π
pi of the projection: f X over Z and f Y over Z.
RT
R-transpose turns a world direction into the camera's axes.
ℓ
ell the landmark's position in the world, in metres.
p
p the camera's position in the world, in metres.
In plain words

Subtract the camera position p from the landmark ell. Turn the result into camera axes with R-transpose. Project it with pi. Subtract that predicted pixel from the measured pixel z. What is left is r.

With numbers

With made-up numbers: f = 500 px, a landmark 0.4 m right and 2.0 m ahead, so z = 100 px. Guess the camera 0.05 m too far right: the landmark is now 0.35 m right, π gives 87.5 px, and r = 100 − 87.5 = +12.5 px.

Push the guess off

Top view. The blue ray is the measured pixel, the teal ray is the prediction from your guess. The bar on the image line is the residual. Move the guessed camera and the guessed depth, then scale the whole world.

+0.050 m
2.00 m

Illustrative pinhole, exact: f = 500 px, the true landmark at 0.4 m across and 2.0 m deep. "World × 2" doubles the landmark, the guessed depth and the camera offset together.

Why pixels and not metres? The camera never measured a 3-D point. Its noise lives in the image, about a pixel of detector jitter. An error in 3-D would need a depth the camera never gave, which is the scale we are trying to find.

Press World × 2. The residual does not move. One view is happy with every point along a ray, at every scale. Only many views and the IMU pin the point down. VNAV 5 adds lens distortion and the full camera matrix.

Failure: an uncalibrated lens. Symptom: residuals are small near the image centre and large near the edges, and the path bends. Measure: plot the residual against the distance from the centre. Fix: calibrate the intrinsics and distortion first (Lesson 15).
Why does VIO score the camera in pixels instead of 3-D distance?

Chapter 3

One Cost, Two Machines

Put both sensors into one cost, then choose to filter it once or re-solve a window

There are two ways to wire the sensors. Loosely coupled VIO runs visual odometry on its own, then blends its finished pose with the IMU. Tightly coupled VIO feeds every feature residual and every IMU term into one estimator. Tight coupling lets the IMU's metres and the camera's shape pull on the same variables, and that is how the filter finds the scale.

Tight coupling is one cost. Call everything we estimate X: poses, velocities, IMU biases and landmarks. Call each visual residual from Chapter 2 rvis. Call each IMU residual rimu: the measured motion between two frames against the motion of the poses. Divide each by its own noise σ, and pixels and metres per second become comparable.

Say it aloud

J of X equals the sum of r-vis over sigma-vis, squared, plus the sum of r-imu over sigma-imu, squared.

J(X)
J of X the total cost of one guess X; the best X makes it smallest.
∑
the sum over one term per measurement: every feature in every frame, every IMU interval.
rvis
r-vis a reprojection residual from Chapter 2, in pixels.
σvis
sigma-vis the pixel noise, about 1 px.
rimu
r-imu an IMU residual: the measured motion between two frames against the motion of the poses.
σimu
sigma-imu the noise of that IMU residual, in its own unit.
In plain words

For a guess X, compute every r-vis and every r-imu. Divide each by its sigma and square it. Add them all. That is J. VIO searches for the X with the smallest J.

With numbers

With made-up numbers: a 2 px residual with 1 px noise adds (2/1)² = 4. A velocity residual of 0.02 m/s with 0.01 m/s noise adds (0.02/0.01)² = 4. Measured in its own noise, each sensor gets an equal say.

Two machines minimise J. A filter, like the MSCKF of Chapter 4, takes each measurement once. It linearises at the estimate it has, updates, and forgets. A sliding-window optimiser, like OKVIS (Leutenegger et al. 2015) and VINS-Mono (Qin et al. 2018), keeps the last few seconds of poses. At each frame it re-solves the window with Gauss-Newton and relinearises at every step (VNAV 9).

Start from a bad guess

Six camera positions (blue) see one landmark 4 m away. Warm marks where a filter ends, teal where a window ends. Move the first depth guess.

8.0 m

Illustrative, seeded: cameras 0.2 m apart along a line, f = 500 px, 1 px noise, the landmark at 0.5 m across and 4.0 m deep. Prior depth sigma 3 m. The filter does one EKF update per view; the window runs Gauss-Newton on all six views to convergence.

From a guess of 4 m both end near the truth. From 8 m the filter ends at 4.49 m, because it linearised the first views far from the answer and kept those slopes. The window ends at 3.97 m from any start: it reuses old views with new slopes. That costs more work, and it is why optimisers are usually more accurate (Huang 2019).

ChoiceWhat it doesCost
LooseVO pose blended with the IMUcheap; the scale and cross-talk are lost
Tightevery residual in one costmore states; finds the scale
Filter (MSCKF)linearise once, update, forgetbounded and small
Window (OKVIS, VINS-Mono)re-solve the last few secondsmore compute; usually more accurate
Failure: loose coupling and a drifting scale. Symptom: the fused path stretches slowly although the IMU is good. Measure: compare the VO scale against a known distance over time. Fix: couple tightly, so the scale is a variable the IMU can correct.
Why is a sliding-window optimiser usually more accurate than a filter?

Chapter 4

Use a Landmark, Then Throw It Away

Project a feature track onto the null space of its landmark, and keep only what it says about the poses

The plain way to put a camera into an EKF is EKF-SLAM: add every landmark to the state. A thousand landmarks add three thousand numbers, and the covariance grows with the square of that. A headset cannot pay for it.

The Multi-State Constraint Kalman Filter (MSCKF) of Mourikis and Roumeliotis (2007) keeps no landmarks. Its state is the IMU state plus a sliding window of past camera poses, a copy taken at each frame. When a feature track ends, its views constrain the poses that saw it, because one point must explain all of them.

The landmark is in the way. Triangulate it to get a guess, then linearise the stacked residuals: r ≈ HXδX + Hℓδℓ + n. Here δX is the error of the poses, δℓ the error of the landmark, and the two H matrices say how fast r moves with each. Now find a matrix A with orthonormal columns that Hℓ cannot reach.

Say it aloud

A-transpose times H-ell equals zero. So r-o equals A-transpose r, which is about A-transpose H-X delta-X, plus A-transpose n.

AT
A-transpose a projection: its rows are orthonormal directions that H-ell cannot reach, the left null space of H-ell.
Hℓ
H-ell how the residuals change with the landmark: tall, with 3 columns for its 3 coordinates.
0
zero the landmark term vanishes exactly, not by approximation.
ro
r-o the projected residual: what the track says about the poses alone.
r
r all of the track's reprojection residuals, stacked.
HXδX
H-X delta-X how the pose errors move the residuals.
n
n pixel noise; because A has orthonormal columns, A-transpose n is noise of the same size.
In plain words

Find the directions A that the landmark cannot move. Multiply the residual r by A-transpose. The landmark term drops out, and r-o is a normal EKF measurement of the poses. A track of m views gives 2m rows; 3 go to the landmark and 2m − 3 stay.

With numbers

With made-up numbers in one dimension: poses at 0, 2 and 4 m measure the landmark's offset as 10.1, 7.9 and 6.0. With the guess 10, r = (0.1, −0.1, 0.0) and H-ell = (1, 1, 1). Take A's columns as (1, −1, 0)/√2 and (1, 1, −2)/√6. Then r-o = (0.141, 0.000). With the guess 50, r = (−39.9, −40.1, −40.0), and r-o is again (0.141, 0.000).

Move the landmark guess

Left, the raw residuals of the three views. Right, the two projected residuals. Drag the landmark guess and watch which bars move.

10.00

Illustrative one-dimensional track, exact algebra: the measurement is the landmark minus the camera position, so H-ell is a column of ones. In 3-D, H-ell has 3 columns and A comes from a QR decomposition.

The projected numbers say whether the poses agree about one point. They carry nothing about where the point is. So the state holds only poses, and the cost grows linearly with the number of features (Mourikis and Roumeliotis 2007). OpenVINS is a modern open-source MSCKF.

Failure: a track with no baseline. Symptom: the pose jumps when some tracks are used. Measure: the triangulation angle of each track, and its residual against a chi-square gate. Fix: use only tracks seen from several well-spread views; gate the rest.
How does the MSCKF use a landmark without putting it in the state?

Chapter 5

Forget a Pose, Keep What It Taught

Fold the oldest pose into a prior with the Schur complement instead of deleting it

A sliding-window optimiser adds a pose at each keyframe. The window must stay small, so the oldest pose has to go. Delete it with its measurements and you lose what it knew. In our toy below, the first pose held the anchor of the whole chain.

Gauss-Newton solves HδX = b at each step. H is the information matrix: how strongly the measurements pin each variable and each pair of variables. Information adds; covariance is its inverse. Split the variables into the ones to drop, α, and the ones to keep, β. Then H has four blocks: Hαα, Hαβ, Hβα and Hββ.

Say it aloud

H-prime equals H-beta-beta minus H-beta-alpha, times H-alpha-alpha inverse, times H-alpha-beta.

H′
H-prime the information left on the kept variables: the Schur complement. Its new part is the prior.
Hββ
H-beta-beta the information the kept variables already had.
Hβα
H-beta-alpha the links from the kept variables to the dropped pose.
Hαα−1
H-alpha-alpha inverse the dropped pose's own information, inverted: its covariance.
Hαβ
H-alpha-beta the same links the other way; H is symmetric.
In plain words

Solve the dropped pose out of the equations instead of deleting its rows. The kept block H-beta-beta loses the part that only made sense with alpha present, and gains what alpha passed on through the links. The result H-prime is a prior on the kept poses.

With numbers

With made-up numbers: x0 has a prior of sigma 0.05 m (information 400). Its IMU link to x1 has sigma 0.1 m (information 100). H-alpha-alpha = 500, H-alpha-beta = −100, H-beta-beta = 100. H-prime = 100 − 100 × 100 / 500 = 80, so x1 keeps sigma 0.112 m, exactly √(0.05² + 0.1²). Deleting x0 leaves x1 with no anchor at all.

Drop the oldest pose

Five poses on a line (teal) link to each other through the IMU and to one landmark (yellow). Purple bars are each estimate's two-sigma band. Choose how to drop pose x0.

Illustrative linear toy, seeded: true poses at 0 to 4 m and the landmark at 6 m. A prior on x0 of sigma 0.05 m, IMU links of sigma 0.1 m, and a range to the landmark from every pose with sigma 0.3 m. "Delete, fix x1" removes every term on x0 and holds x1 at its current value, as a window without a prior must.

Marginalising gives the same estimates and sigmas as keeping everything, because the problem is linear. Deleting leaves the chain floating. Holding x1 fixed to stop it floating makes the window overconfident: x2 claims a sigma of 0.096 m where the full solve gives 0.140 m. VINS-Mono marginalises with the Schur complement (Qin et al. 2018), and OKVIS marginalises old states too.

Failure: deleting instead of marginalising. Symptom: the estimate jumps a little at every slide of the window, and its sigma is too small. Measure: compare with a full batch solve on a short log. Fix: marginalise, and keep the prior's linearisation point fixed when you relinearise later.
Why does the window marginalise its oldest pose instead of deleting it?

Chapter 6

Integrate the IMU Once per Keyframe

Collapse a hundred IMU samples into one relative motion the optimiser can reuse

Between two keyframes 0.1 s apart, a 1000 Hz IMU gives 100 samples. In the world frame their integral depends on the start attitude, the start velocity and the bias. The optimiser moves all three at every iteration, so it redoes a plain integral each time.

Preintegration (Forster et al. 2017, after Lupton and Sukkarieh) integrates in the first keyframe's axes instead. The rotation ΔR, velocity change Δv and position change Δp then depend only on the samples and the bias, so you compute them once.

Call the keyframes i and j and the samples between them k. Call each accelerometer reading ãk, the bias ba and the sample time Δt. The gyro gives the rotation from frame i to sample k, ΔRik.

Say it aloud

Delta-v-i-j equals the sum over k of Delta-R-i-k times, a-tilde-k minus b-a, times delta-t. Then v-j equals v-i plus g times Delta-t-i-j plus R-i times Delta-v-i-j.

Δvij
Delta-v-i-j the preintegrated velocity change, in the axes of keyframe i.
∑k
the sum over k one term per IMU sample between i and j.
ΔRik
Delta-R-i-k the rotation from keyframe i to sample k, from the gyro alone.
ãk
a-tilde-k the raw accelerometer reading at sample k, in m/s².
ba
b-a the accelerometer bias, held at its current estimate.
Δt
delta-t the time between samples; Delta-t-i-j is the whole interval.
vj
v-j the velocity at keyframe j in the world; v-i at keyframe i.
g
g gravity, 9.81 m/s² down; the accelerometer does not sense free fall, so the formula adds gravity back.
Ri
R-i the attitude of keyframe i: the only place the world attitude enters.
In plain words

Remove the bias b-a from each reading a-tilde-k. Turn it into keyframe i's axes with Delta-R-i-k, multiply by delta-t and add: that is Delta-v-i-j, done once. To use it, turn it into the world with R-i, then add gravity's share and v-i.

With numbers

With made-up numbers in one dimension, with no rotation and no gravity on the axis. Three readings of 2.00 m/s², bias 0.10, Δt = 0.1 s. Δv = 3 × 1.90 × 0.1 = 0.57 m/s and Δp = 0.0855 m. If v-i is 1 m/s, v-j is 1.57 m/s.

The bias still moves. Store how Δv changes with the bias, the bias Jacobian J, and correct with one multiply. Call the bias change δb.

Say it aloud

Delta-v of b plus delta-b is about Delta-v of b, plus J times delta-b.

Δv(b + δb)
Delta-v of b plus delta-b the velocity change the samples would give with the new bias.
Δv(b)
Delta-v of b the stored preintegrated value at the old bias.
J
J the bias Jacobian, stored with it: minus delta-t per sample for the accelerometer bias in one dimension.
δb
delta-b how far the optimiser moved the bias.
In plain words

Take the stored Delta-v. Add J times the bias change delta-b. The samples stay untouched.

With numbers

J = −0.3 s for three samples of 0.1 s. With δb = +0.05 m/s²: 0.57 + (−0.3)(0.05) = 0.555 m/s. Re-integrating with bias 0.15 gives 3 × 1.85 × 0.1 = 0.555: exact, because Δv is linear in the accelerometer bias.

Bend the gyro bias

One second of a turning rig at 100 Hz. Warm dots: step-by-step world integration. Teal ring: the preintegrated end. Move the gyro-bias change and compare the purple ring (one multiply) with the dashed ring (full re-integration).

10.0°/s

Illustrative planar toy: 100 samples over 1 s, yaw rate 0.5 + 0.3 sin(2t) rad/s, forward acceleration 0.3 m/s², start speed 1 m/s. We draw the endpoint shift 10 times larger than the path.

The endpoints agree to within 10−14 m, because preintegration only rearranges the integral. The gyro-bias fix is first order: double the change and its miss grows about four times.

Failure: a stale linearisation point. Symptom: IMU residuals stay large after the bias estimate moves far. Measure: the bias change since each factor was built. Fix: past a threshold, re-integrate that factor from its samples.
Why does preintegration let the optimiser avoid re-integrating the IMU at every iteration?

Chapter 7

Four Things VIO Can Never Know

Move the whole answer without changing the cost, then see why gravity pins the tilt

VIO measures motion, not place. Move every pose and every landmark 2 m east. Every pixel stays the same, and so does every IMU reading. Turn everything 30° about the vertical. Again nothing changes, because the accelerometer still feels gravity straight down.

Now tilt everything by 5°. The accelerometer should now feel gravity at a slant, and it does not. The cost rises, so tilt is observable: the measurements can tell it apart. Call a move of the whole answer Tg, made of a shift t and a turn ψ about gravity.

Say it aloud

J of T-g applied to X equals J of X, where T-g is a shift t and a turn psi about gravity.

J
J the cost of Chapter 3.
Tg
T-g a rigid move of the whole answer that keeps gravity pointing down.
∘
applied to move every pose and every landmark by the same T-g.
X
X all the estimated poses, velocities and landmarks.
(t, ψ)
t and psi a shift in three directions and one turn about the vertical: four numbers.
In plain words

Shift every pose and landmark by t, and turn all of them by psi about the vertical. The cost J does not change. So no measurement can choose t or psi: global position and yaw are the four unobservable directions.

With numbers

In a seeded toy with 6 poses and 8 landmarks (60 unknowns, pixels, gyro and accelerometer terms), the Jacobian has exactly 4 zero singular values. Shifting 2 m or turning 30° leaves the cost at 0. A 5° tilt moves the felt gravity by 9.81 × 2 sin 2.5° = 0.86 m/s².

Move the whole answer

Top view of the estimate (teal) and its landmarks (yellow) over the truth (dashed). The pink gauge shows gravity as the accelerometer feels it. Shift, turn and tilt.

0.0 m
0°
0.0°

Illustrative, exact for this geometry: a shift or a turn about gravity changes no pixel and no IMU reading. The tilt read-out compares the gravity shift with an accelerometer noise of 0.05 m/s².

So VIO needs a start. The estimator refines; it does not invent. VINS-Mono starts with vision-only structure from motion over a window, then aligns it with the preintegrated IMU. That gives the gyro bias, the velocities, the gravity direction and the metric scale; it leaves the accelerometer bias for later (Qin et al. 2018). The motion must accelerate and turn, which is why a headset asks you to look around.

A plain EKF has one more trap. Linearised at its current estimate, it can see only three unobservable directions instead of four, and it gains false confidence in yaw (Huang 2019). First-estimate Jacobians and observability-constrained filters fix this.

Failure: a world born tilted or the wrong size. Symptom: the path dives into the floor, or every distance is off by the same factor. Measure: the gravity estimate against 9.81 m/s², and a known 1 m walk. Fix: demand enough acceleration and rotation before you accept the start; restart if the first residuals are large.
Why are roll and pitch observable in VIO while yaw is not?

Chapter 8

Showcase: Walk the Figure Eight

Run the whole filter, blind the camera, starve it of acceleration, and start it with a bad scale

Here is the hero's filter with every control. It is a tightly coupled EKF with seven states: position, velocity, accelerometer bias and the inverse scale. The IMU predicts at 100 Hz. At 10 Hz the camera reports a position in visual units, and the filter compares it with the predicted position times the inverse scale.

Run the whole filter

The map shows the truth (dashed), the camera alone (blue), the IMU alone (warm) and the fused path (teal). Right: the fused error, and the scale estimate with its two-sigma band against the true 1.8. Choose the motion, the blank wall and the first scale guess.

4 s
1.0

Illustrative planar toy, seeded, the same walk as the hero. Straight cruise: 1 m/s in a straight line, no acceleration. The blank wall starts at 14 s. The first scale guess sets the filter's starting lambda, with a sigma of 0.5 on its inverse.

Start with the defaults. The scale estimate starts at 1.0 and is within 5% of 1.8 after 7.5 s, as the turns supply acceleration. The 4 s blank wall costs at worst 0.17 m. An IMU alone with the same bias drifts 0.58 m in 4 s from a perfect start. The fused filter coasts better because it learned the bias first.

Now choose Straight cruise. With no acceleration the scale is unobservable (Chapter 1). The estimate stops at 1.16 and claims a sigma of 0.02, while the truth is 1.8: wrong and sure of itself. After 30 s the fused path is 10.6 m off.

Last, the start. A first guess of 1.8 locks in 2.7 s. A guess of 3.0 takes 12.3 s. A guess of 0.5 diverges: the linearisation is so wrong that each update makes it worse.

Failure: a filter that is wrong and certain. Symptom: the scale sigma is small but distances are off. Measure: the recent acceleration, and a known distance. Fix: treat the scale as unknown until the motion has excited it; flag long straight runs.
In the straight cruise, the scale estimate settles at 1.16 with a sigma of 0.02. What happened?

Chapter 9

Read the Symptom

Match each failure to its signature: blank walls, pure rotation, rolling shutter and the rest

VIO fails in a few ways, and each leaves its own signature. The deepest one is pure rotation. A camera that turns on the spot sees every feature move, but no feature gets a new viewpoint. Depth comes from two views a baseline apart, and a turn on the spot has a baseline of zero.

Two views a baseline b apart see a point at depth Z. The point shifts between the images by the disparity d = f b / Z. Call the pixel noise σu. Differentiate Z = f b / d and the depth doubt follows.

Say it aloud

Sigma-Z equals Z squared times sigma-u, over f times b.

σZ
sigma-Z the doubt of the triangulated depth, in metres.
Z2
Z squared the depth, squared: far points are much worse.
σu
sigma-u the pixel noise, about 1 px.
f
f the focal length in pixels.
b
b the baseline: how far the camera moved between the views, in metres.
In plain words

Square the depth Z. Multiply by the pixel noise sigma-u. Divide by f times the baseline b. As b goes to zero, sigma-Z grows without limit.

With numbers

With Z = 4 m, σu = 1 px and f = 500 px: a 0.1 m baseline gives 16 / 50 = 0.32 m. A 0.01 m baseline gives 3.2 m. A pure rotation gives no depth at all.

Shrink the baseline

Two cameras (blue) see one landmark (yellow) 4 m away. The purple band is the depth doubt, plus and minus one sigma. Slide the baseline toward a pure rotation.

0.100 m

Illustrative, first order: f = 500 px, 1 px noise, depth 4 m. We draw the baseline 12 times wider than to scale so short ones show; depths are to scale.

SymptomCauseFix
Shaky or lost on a blank wall, in the dark, in a fast blurtoo few featurescoast on the IMU; watch the feature count
Depth jumps while turning on the spotpure rotation: no baselinedo not triangulate new points until the camera translates
Skew that grows with turn ratea rolling shutter reads rows at different timesgive each row its own time, or use a global shutter
Error that grows with speeda camera-IMU time offsetestimate the offset online (Lesson 15)
Every distance off by one factor; a tilted worlda bad startmore motion before accepting the start; restart
Scale wanders in a steady cruiseno accelerationmanoeuvre, or add a metric sensor
One sudden, unrecoverable jump after a knockIMU saturation: readings pegged at the limita wider-range IMU; distrust pegged samples
Slow, steady drift over a long walkodometry by natureloop closure (VNAV 12, VNAV 13)

Two of these are quick sums, with illustrative numbers. A rolling shutter takes 30 ms to read the frame. Turning at 2 rad/s with f = 500 px, the image skews by 500 × 2 × 0.03 = 30 px top to bottom. A 5 ms time offset at the same turn rate puts every feature 5 px off.

Failure: triangulating during a pure turn. Symptom: new landmarks appear at wild depths and the scale jumps. Measure: the parallax angle of each new track. Fix: wait for translation; until then, use the gyro and the old landmarks.
A headset turns on the spot. Why does it not create new landmarks?

Chapter 10

Field Guide

Keep the equations, the numbers, the checklist and the code in one place

The IMU predicts at its own rate. The camera supplies reprojection residuals that fix the drift, and the IMU's metres fix the scale. A filter takes each residual once and projects the landmark away. A window optimiser re-solves the last few seconds, marginalises the oldest pose and reuses preintegrated IMU factors. Position and yaw stay free; motion must excite the rest.

QuantityFormulaNumbers from this page
Projectionu = f X / Z0.4 m at 2 m and 0.8 m at 4 m: both 100 px
Scaleλ = aΔt² / (s2 − 2s1 + s0)0.4 / 0.222 = 1.8
Residualr = z − π(RT(ℓ − p))100 − 87.5 = +12.5 px
CostJ = ∑(rvis/σvis)² + ∑(rimu/σimu)²2 px in 1 px noise adds 4
MSCKFATHℓ = 0, ro = ATr(0.141, 0.000) for any landmark guess
MarginaliseH′ = Hββ − HβαHαα−1Hαβ100 − 20 = 80: sigma 0.112 m
PreintegrateΔvij = ∑ΔRik(ãk − ba)Δt0.57 m/s; 0.555 after δb = 0.05
GaugeJ(Tg ∘ X) = J(X)4 zero singular values of 60
Depth doubtσZ = Z²σu / (f b)0.32 m at b = 0.1 m; 3.2 m at 0.01 m

Checklist

  1. Calibrate the camera intrinsics, the camera-IMU extrinsics and the time offset first.
  2. Run the IMU fast (hundreds of Hz) and the camera slower; the IMU fills the gaps.
  3. Couple tightly: every residual in one cost, the scale and biases as variables.
  4. Start only after the motion has accelerated and turned; check gravity and scale.
  5. Choose keyframes with real baseline; do not triangulate during pure rotation.
  6. Marginalise old poses; never delete them.
  7. Preintegrate the IMU between keyframes; re-integrate when the bias moves far.
  8. Watch the feature count, the residuals and the scale sigma; coast on the IMU through blank walls.
pythonimport numpy as np

def msckf_project(r, H_X, H_L):
    # left null space of the landmark Jacobian: A.T @ H_L == 0, A.T @ A == I
    Q, _ = np.linalg.qr(H_L, mode='complete')
    A = Q[:, H_L.shape[1]:]
    return A.T @ r, A.T @ H_X              # a pose-only EKF measurement

def marginalise(H, b, drop):
    # Schur complement: remove variables 'drop', keep their information as a prior
    keep = np.setdiff1d(np.arange(H.shape[0]), drop)
    Hai = np.linalg.inv(H[np.ix_(drop, drop)])
    Hkd = H[np.ix_(keep, drop)]
    H2 = H[np.ix_(keep, keep)] - Hkd @ Hai @ Hkd.T
    b2 = b[keep] - Hkd @ Hai @ b[drop]
    return H2, b2

def preintegrate(acc, gyro, dt, ba, bg):
    # planar: returns dtheta, dv, dp in the frame of the first keyframe
    th, dv, dp = 0.0, np.zeros(2), np.zeros(2)
    for a, w in zip(acc, gyro):
        c, s = np.cos(th), np.sin(th)
        ak = np.array([[c, -s], [s, c]]) @ (a - ba)
        dp = dp + dv * dt + 0.5 * ak * dt * dt
        dv = dv + ak * dt
        th = th + (w - bg) * dt
    return th, dv, dp                          # reuse at every optimiser iteration

Where it runs

SystemMachineNotes
VINS-Monosliding-window optimiserHKUST; preintegration, robust start, extrinsic calibration, loop closure with a 4-DOF pose graph
OKVISkeyframe optimisernonlinear optimisation over keyframes with marginalisation
OpenVINSfilter (MSCKF)open-source MSCKF platform
Phone ARproprietaryApple describes ARKit's world tracking as visual-inertial odometry

VIO is INS/GNSS coupling with a camera in place of satellites: the same IMU, a different partner that bounds its drift. The partner does not give absolute position, so VIO still drifts, slowly.

Keep going

References

The takeaway. The camera gives the shape, the IMU gives the size and the gaps. Put both in one cost, keep what old poses taught, and make the motion excite what you want to know.
A colleague wants to drop the IMU because the camera barely drifts. What is lost?

Now press Present or Teach and derive it from memory. Cover the projection, the scale, the residual, the null-space projection, the Schur complement, preintegration and the four free directions. Then go back to the figure eight, set the blank wall to 8 s, and say why the fused path comes back.

Credit

Lesson 16 of 22 in Sensor Fusion: Classical to Modern on Engineermaxxing. The structure follows Mourikis and Roumeliotis (2007), Forster et al. (2017), Qin et al. (2018) and Huang (2019). Every toy number on this page carries the word illustrative.

Sensor Fusion: Classical to Modern · Lesson 16: Visual-Inertial Odometry
Previous: Calibration and Time Sync · Next: LiDAR-Inertial Factor Graphs · Back to Gleams