TL;DR
Visual SLAM, short for simultaneous localisation and mapping, lets a robot or phone with only a camera work out where it is while it builds a map of what surrounds it. It finds distinctive points in each image, matches them over time, triangulates them into 3D, and continually refines the camera's path and the map together. Without an outside reference the estimate drifts, so systems also recognise places they have seen before and correct the accumulated error.
Where you'll see it: in the tracking of drones and robot vacuums that have no GPS indoors, in the world-tracking behind augmented reality on phones, and in self-driving stacks that fuse camera data with other sensors.
Intuition
Localise yourself and map the room at once
Imagine walking through an unfamiliar building blindfolded except for a camera on your head. To know where you are, you need a map. To build a map, you need to know where you are. Each depends on the other, and SLAM is the method for solving both at once.
The camera gives you snapshots. In each one you pick out a few hundred corners and textured spots, which are easy to find again from a slightly different angle. As you move, the same spots shift across the image. Their shift, together with the geometry of two views, tells you how the camera moved and where the spots are in 3D. A sequence of such estimates is the trajectory, and the spots form the map.
Why it drifts, and how it is fixed
Every estimate carries a small error, and the errors add up. A camera that turns 1 degree wrongly at each step ends up pointing in a completely different direction after a few hundred steps. This is drift. SLAM fights it in two ways. Locally, it refines the recent poses and points together so they agree with all the images. Globally, when the camera returns to a place it has seen, it recognises the place and pulls the whole trajectory back into shape. That second step is called loop closure.
flowchart LR
A[New image] --> B[Track features against the map]
B --> C[Estimate camera pose]
C --> D[Triangulate new points]
D --> E[Refine poses and points locally]
E --> F{Revisited a known place?}
F -- yes --> G[Loop closure and global correction]
F -- no --> A
G --> A
The math
Unknowns
SLAM estimates two kinds of quantity. Each camera pose is a rigid motion: a rotation and a translation , which together move a world point into camera coordinates as . This is the rigid body transformation that packs the rotation and translation into one matrix. Each map point is a 3D position . The camera projects a point through the pinhole model with calibration matrix , and denotes the division by depth that turns camera coordinates into pixels.
Reprojection error
The measurement is the pixel where point was seen in frame . The model predicts . The error is the difference, and SLAM minimises the sum of squared differences over all observations (the sign of each difference does not matter once squared; the examples below compute predicted minus measured):
This is a nonlinear least-squares problem, because the projection divides by depth and the rotations are nonlinear in their parameters. It is solved by the same method as in nonlinear least squares: linearise the residuals, solve a linear system for an update, apply it, and repeat. When the poses and points are optimised together over a window of recent frames, this is called bundle adjustment.
Structure of the problem
Each observation involves one camera and one point, so the Jacobian is sparse. Most entries are zero because a point is seen by only a few cameras. Solvers exploit this sparsity, which is what makes bundle adjustment over a window of recent frames fast enough for real time.
Scale ambiguity
A single moving camera cannot recover absolute scale. Scale every camera translation and every point by the same factor , and the predicted pixels do not change, because divides out the scale. The reconstruction is only known up to a global scale. Monocular SLAM therefore needs a reference, such as a known baseline between the first two frames, an object of known size, or an inertial sensor, to fix the scale.
Pose graphs
Once the map is large, optimising every point is expensive. A common approach keeps only keyframe poses and the relative motions between them, a pose graph. Each edge says how one keyframe is positioned relative to another, and loop closures add extra edges between distant keyframes. Solving the pose graph spreads the correction along the trajectory.
Worked examples
Take a point at in camera coordinates, with for simplicity. The true pose has zero translation. The measured pixel is .
- The predicted horizontal coordinate is , so the residual is .
- Suppose the tracked pose has a translation error along the -axis. The predicted point is , so .
- The residual is , and the squared error is .
- Interpretation: a 0.1-unit error in position at depth 4 shows up as a 0.025 error in normalised image coordinates. The optimiser reduces the total over all points and frames until the residuals are as small as the noise allows.
The plot shows the residual as the translation error changes. Here the residual is simply , so the marked point is with residual 0.025.
- residual = t / 4
Start with the camera at the origin and a point at with . Its image is .
- Add a second camera, translated by from the first, which sees the point at .
- Scale the whole scene by : the point becomes and the translation becomes .
- The first camera still sees . The second sees . Both images are unchanged.
- Interpretation: the images cannot tell a scene of size 1 from one of size 2. A monocular system must bring in a known length, such as the baseline of its first two frames, before its map has real units.
Suppose a camera's estimated step lengths are 1 percent too long, and it travels 100 metres in a straight line. The estimated path is 101 metres long, so the position error is 1 metre, or 1 percent of the distance travelled. The same 1 percent over a longer path adds proportionally more error, which is the drift that loop closure is meant to remove.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Featureless walls or blur | Few features are tracked, and the pose estimate fails or jumps. | Add an inertial sensor for short gaps, or wait for texture to return. |
| Fast rotation | Features move too far between frames to match. | Use higher frame rates, or predict the motion first. |
| Dynamic objects | Moving people or cars are treated as static points and corrupt the map. | Mask dynamic regions or reject inconsistent points. |
| Repetitive patterns | Loop closure matches the wrong place. | Verify candidate loops geometrically before accepting them. |
| Monocular only | Scale is unknown, and drift is not bounded by any measurement. | Fuse an IMU, a stereo pair or a wheel odometer. |
| Full bundle adjustment on every frame | Cost grows too fast for real time. | Optimise a sliding window, and run global pose-graph optimisation in the background. |
Visual SLAM has no single best design. Feature-based systems are robust and widely used. Direct methods, which work on pixel intensities, can use more of the image but are more sensitive to lighting changes.
History
The problem comes from robotics in the 1980s, when Smith, Self and Cheeseman and others described how a robot could maintain a map and its own position using probabilistic estimates. Through the 1990s the joint estimation view was developed, mostly with range sensors such as lasers and sonar, and the name SLAM became standard in the mid-1990s.
Camera-based versions became practical in the 2000s, as cheap cameras and faster processors made it possible to track hundreds of points per frame. Monocular systems that ran in real time on a laptop appeared in the early to mid 2000s, for example Andrew Davison's MonoSLAM and, later, Klein and Murray's PTAM, and the feature-based approach that combined tracking, mapping and loop closure became the common design in the following decade. Mobile devices later brought the same ideas into augmented reality.