VIO and SLAM
UAT 307 Computer Vision and Perception Technology
Lesson
By the end of this module you will be able to
- Distinguish VIO, VIN and SLAM by the roles of camera, IMU and map
- Compute depth from a stereo camera and its depth error
- Explain the scale problem of a single camera and estimate scale from an IMU
- Fuse IMU and camera positions with a Kalman filter that also estimates accelerometer bias
- Choose perception sensors to suit range and environment
Why this matters
The drone knowledge base’s unit on VIN, VIO and SLAM explains the roles of the camera, IMU and data fusion before choosing navigation tools. VIO (visual-inertial odometry) estimates continuous motion from a camera and IMU. SLAM builds a map and localises within it at the same time, and can close loops to reduce drift. This module focuses on depth and scale, the two things that most often make visual navigation go wrong.
Stereo depth
Two cameras separated by a baseline see the same point at different image positions. The difference is the disparity , and depth is , where is the focal length in pixels. Because is inversely proportional to , a small disparity error causes large depth errors at long range, growing with the square of range, following the relation that Keselman et al. (2017) use to describe Intel RealSense stereo depth cameras.
Example 1 A small stereo camera on a drone
Focal length 640 pixels, baseline 95 mm and disparity error 0.25 pixel (hypothetical values).
F_PX, BASE, DD = 640, 0.095, 0.25 # pixels, m, pixels
for z in (2, 5, 10, 20):
d = F_PX * BASE / z
dz = z * z / (F_PX * BASE) * DD
print(f"range {z:>2} m: disparity {d:5.2f} px, depth error about {dz:.3f} m ({dz / z:.1%})")
range 2 m: disparity 30.40 px, depth error about 0.016 m (0.8%)
range 5 m: disparity 12.16 px, depth error about 0.103 m (2.1%)
range 10 m: disparity 6.08 px, depth error about 0.411 m (4.1%)
range 20 m: disparity 3.04 px, depth error about 1.645 m (8.2%)
At 2 m the depth is off by only a couple of centimetres, but at 20 m it is off by more than a metre. Small stereo cameras therefore suit close-range obstacle avoidance; for depth at long range, increase the baseline or resolution, or use LiDAR.
Single-camera scale
A single camera knows the direction of motion but not the scale: a real house far away and a model house nearby can look the same. VIO solves this with an IMU, which measures acceleration in real units. Comparing visual displacement (unitless) with IMU-integrated displacement over short periods gives a scale factor. There must be enough acceleration for the IMU to measure clearly, so long periods at constant speed make scale hard to estimate.
Example 2 Estimating scale with least squares
Displacements over six short periods from the IMU (metres) and from images (unitless), with a true scale of 3.2 (simulated data).
import numpy as np
imu = np.array([0.52, 1.05, 1.48, 2.10, 2.47, 3.03]) # m
vis = imu / 3.2 + np.random.default_rng(8).normal(0, 0.01, 6) # unitless
s = (vis @ imu) / (vis @ vis)
resid = imu - s * vis
print("visual displacements:", np.round(vis, 3))
print(f"estimated scale {s:.3f} (true 3.2), residual RMS {np.sqrt(np.mean(resid ** 2)):.3f} m")
print(f"a 10-unit visual path would be {10 * s:.1f} m")
visual displacements: [0.145 0.315 0.449 0.653 0.749 0.945]
estimated scale 3.250 (true 3.2), residual RMS 0.034 m
a 10-unit visual path would be 32.5 m
The estimated scale is close to the true value, and the residual indicates estimate quality. A scale error of just 5% makes a 100 m path wrong by 5 m, so VIO systems estimate scale continuously throughout the flight, and some use a rangefinder or barometer to confirm it.
Fusing camera and IMU with a Kalman filter
Sensor fusion combines sensors whose weaknesses differ so that the result is better than any one of them. The camera and IMU are the classic pair. The IMU measures acceleration and rotation hundreds of times per second in real units, but integrating acceleration twice turns any small bias (a constant offset) into a position error that grows with the square of time. The camera, through visual odometry, gives position with no long-term growth in error, but at a lower rate, with noise, and with gaps when the view has no texture. The Kalman filter from Module 3 fuses them: the predict step moves the state forward with every IMU sample, and the update step corrects it whenever a camera position arrives, weighting each source by its uncertainty through the Kalman gain (Welch and Bishop, 2004; Groves, 2013). Adding the accelerometer bias to the state lets the filter estimate the bias itself from the camera corrections.
Real VIO works in three dimensions with rotations, so it uses nonlinear versions. The extended Kalman filter (EKF) linearises the model around the current estimate, and the MSCKF (Mourikis and Roumeliotis, 2007) keeps a window of recent camera poses so that feature tracks constrain the motion; OpenVINS is an open research platform built on this filter family, while VINS-Mono uses optimisation instead. ArduPilot’s EKF3 applies the same principle in the flight controller, fusing gyroscopes and accelerometers with GPS, compass, barometer and optional sensors such as optical flow.
Example 3 A one-axis camera–IMU Kalman filter
A drone sways forward and back along one axis for 20 s. The IMU gives acceleration at 100 Hz with a bias of 0.08 m/s² and noise; the camera gives position at 10 Hz with 5 cm noise. The state is position, velocity and accelerometer bias. We compare IMU-only dead reckoning, the camera alone and the fused estimate (simulated data, assumed values).
import numpy as np
rng = np.random.default_rng(6)
DT, T = 0.01, 20.0 # IMU at 100 Hz for 20 s
n = int(T / DT)
t = np.arange(n) * DT
acc_true = 0.5 * np.sin(0.5 * t) # the drone sways forward and back
vel_true = np.cumsum(acc_true) * DT
pos_true = np.cumsum(vel_true) * DT
BIAS = 0.08 # accelerometer bias, m/s^2 (assumed)
acc_imu = acc_true + BIAS + rng.normal(0, 0.05, n)
CAM_EVERY, CAM_SD = 10, 0.05 # camera position at 10 Hz, 5 cm noise
cam = pos_true + rng.normal(0, CAM_SD, n)
F = np.array([[1, DT, -0.5 * DT**2], [0, 1, -DT], [0, 0, 1]]) # state: position, velocity, bias
B = np.array([0.5 * DT**2, DT, 0])
H = np.array([[1.0, 0, 0]])
Q = np.diag([1e-6, 1e-4, 1e-7])
R = np.array([[CAM_SD**2]])
x, P = np.zeros(3), np.diag([0.01, 0.01, 0.01])
dead = np.zeros(2) # IMU-only dead reckoning
err_fused, err_dead, err_cam = [], [], []
for k in range(n):
x = F @ x + B * acc_imu[k] # predict with the IMU
P = F @ P @ F.T + Q
dead = np.array([dead[0] + dead[1] * DT + 0.5 * acc_imu[k] * DT**2, dead[1] + acc_imu[k] * DT])
if k % CAM_EVERY == 0: # correct with the camera
S = H @ P @ H.T + R
K = P @ H.T @ np.linalg.inv(S)
x = x + (K @ (cam[k] - H @ x)).ravel()
P = (np.eye(3) - K @ H) @ P
err_cam.append(cam[k] - pos_true[k])
err_fused.append(x[0] - pos_true[k])
err_dead.append(dead[0] - pos_true[k])
rms = lambda e: np.sqrt(np.mean(np.square(e)))
print(f"IMU only: error after 20 s {err_dead[-1]:.2f} m")
print(f"camera only: RMS error {rms(err_cam):.3f} m at 10 Hz")
print(f"fused: RMS error {rms(err_fused):.3f} m at 100 Hz, estimated bias {x[2]:.3f} m/s^2 (true {BIAS})")
IMU only: error after 20 s 16.08 m
camera only: RMS error 0.047 m at 10 Hz
fused: RMS error 0.026 m at 100 Hz, estimated bias 0.076 m/s^2 (true 0.08)
The IMU alone drifts by 16 m in 20 s, which matches the formula for a constant bias, m. The camera alone is accurate to about 5 cm but only 10 times per second. The fused estimate is available at the IMU’s 100 Hz, is more accurate than the camera alone (about 2.6 cm RMS), and has estimated the bias (0.076 against a true 0.08 m/s²). If the camera drops out, over water or in the dark, the filter continues on the IMU with the bias already removed, so it drifts far more slowly than raw dead reckoning; this is why the time offset of Module 2 and the scale of this module must be right, since both enter the same filter.
Choosing perception sensors
- Stereo gives dense depth at short range and works when there is enough texture and light
- LiDAR gives accurate range farther out, independent of light, but is heavier and more expensive
- A single camera with an IMU is light and cheap but needs enough motion to find scale
- All of them struggle with smooth textureless surfaces, reflective surfaces, water and fog
Module lab
Lab: depth and scale
- Measure stereo depth at 1–10 m, compare with true range and with Example 1
- Change the background to a smooth, textureless wall and observe where depth disappears
- Use recorded camera and IMU data to estimate scale with Example 2
- Compare scale during acceleration with scale during constant-speed flight
- Run Example 3, remove the camera corrections between seconds 10 and 15 (simulating flight over water) and compare the error with a filter that has no bias in its state
- Write a proposal for choosing perception sensors for a drone inspecting the underside of a bridge
Common mistakes
Watch out
- Trusting stereo depth at long range
- Using a single camera with no source of scale
- Flying at constant speed throughout, so VIO cannot find scale
- Relying on visual perception over water or smooth ground without a backup
- Fusing camera and IMU without modelling IMU bias, so the filter trusts a drifting sensor
- Confusing VIO with SLAM and assuming it closes loops
Summary
- VIO estimates motion from camera and IMU; SLAM adds a map and loop closure
- Stereo depth , with error growing as the square of range
- A single camera does not know scale; an IMU can estimate it when there is enough acceleration
- A Kalman filter predicts with the IMU, corrects with the camera and can estimate the IMU bias, giving output at the IMU rate without long-term drift
- Choose sensors for the job’s range, lighting and surfaces
Check your understanding
- With = 700 px, = 0.1 m and = 14 px, what is the depth?
- If range doubles, by what factor does depth error grow?
- Why does a single camera not know scale?
- An accelerometer has a bias of 0.05 m/s². Using the IMU alone for 10 s, how large is the position error?
- How does SLAM differ from VIO?
Answers
- m
- 4 times
- A large distant object and a small near object produce the same image
- m
- SLAM builds a map and closes loops when returning to a place, so it reduces accumulated drift
Key formulas
| Kalman gain | |
| Stereo depth | |
| Depth error | |
| Least-squares scale |
Key references
- Szeliski, R. (2022). Computer vision: Algorithms and applications (2nd ed.). Springer. link
- Corke, P. (2023). Robotics, vision and control: Fundamental algorithms in Python. Springer. link
- Hartley, R., & Zisserman, A. (2004). Multiple view geometry in computer vision (2nd ed.). Cambridge University Press. link
- Keselman, L., Woodfill, J. I., Grunnet-Jepsen, A., & Bhowmik, A. (2017). Intel RealSense stereoscopic depth cameras (arXiv:1705.05548). link
- Welch, G., & Bishop, G. (2004). An introduction to the Kalman filter (TR 95-041). University of North Carolina at Chapel Hill. link
- Groves, P. D. (2013). Principles of GNSS, inertial, and multisensor integrated navigation systems (2nd ed.). Artech House. link
- Mourikis, A. I., & Roumeliotis, S. I. (2007). A multi-state constraint Kalman filter for vision-aided inertial navigation. In Proceedings 2007 IEEE International Conference on Robotics and Automation (pp. 3565-3572). https://doi.org/10.1109/ROBOT.2007.364024 link
- Geneva, P., Eckenhoff, K., Lee, W., Yang, Y., & Huang, G. (2020). OpenVINS: A research platform for visual-inertial estimation. In 2020 IEEE International Conference on Robotics and Automation (pp. 4666–4672). link
- Qin, T., Li, P., & Shen, S. (2018). VINS-Mono: A robust and versatile monocular visual-inertial state estimator. IEEE Transactions on Robotics, 34(4), 1004–1020. link
- ArduPilot Dev Team. Extended Kalman filter (EKF). ArduPilot Copter documentation. link
Further reading
Study the assigned knowledge units in advance, review media and take the module quiz
In class / field
Lecture, case discussion and in-class problem solving
Learning evidence: Quiz results and submitted exercises