TL;DR
Loop closure is the step where a robot notices that it has returned to a place it has seen before. It compares the current view with stored views, checks that the match is geometrically real, and adds a constraint saying the two moments describe the same place. That constraint lets the robot's whole trajectory be corrected, removing the drift that builds up while it moves.
Builds on: Bag of Visual Words, Pose Graph Optimization · Leads to: Visual SLAM, Factor Graph
Where it's used
Warehouse robots. A robot that drives the same aisles for hours accumulates wheel-slip error. When it passes a shelf it has already mapped, loop closure lets it snap its map back into agreement with the shelf's known position.
Phone and headset tracking. A handheld device building a map of a room needs to recognise the doorway it started from. Without loop closure, walking a full circle leaves the map with a visible seam where the start and end meet.
Self-driving research. Long drives in urban areas revisit the same streets. Systems such as the one in the ORB-SLAM paper recognise returns to earlier places and use them to keep the map consistent over kilometres.
How it works
Take a robot that drives down a corridor, turns, and comes back toward its start. Its visual features are summarised as a bag-of-words histogram over a vocabulary of three visual words, A, B and C. Its wheel odometry drifts, so the robot believes it has moved further than it has.
- Describe the current view. The robot extracts local features from the camera image and counts how many fall into each visual word. Check: the current view gives counts .
- Search the memory of past views. The robot compares the current histogram with stored histograms of earlier views, using a similarity score. Check: the stored view scores against the current view, and the stored view scores . The best candidate is .
- Ignore the recent past. A view taken a second ago always looks similar, so candidates from the last few seconds are discarded. Only older views can close a loop.
- Check the geometry. The robot matches feature points between the two images and uses RANSAC to fit a Rigid Body Transformation that explains the matches. If enough matches agree with one transformation, the match is accepted. A look-alike hallway that fails this test is rejected.
- Add the constraint and optimise. The accepted transformation becomes a new edge in the pose graph between the current pose and the earlier one. Optimising the whole graph moves every pose a little so that all the measurements agree. The drift is shared across the trajectory instead of sitting at the end.
flowchart LR
A[Describe current view] --> B[Search past views]
B --> C{Old enough?}
C -->|no| A
C -->|yes| D{Geometry agrees?}
D -->|no| A
D -->|yes| E[Add loop edge]
E --> F[Optimise pose graph]
- odometry only
- after loop closure
The math
A loop closure edge is a measurement between two poses and that the robot has decided are at the same place in the world, even though they are far apart in time. It is added to the pose graph alongside the ordinary odometry edges, and it carries a weight that says how much the robot trusts it.
Step 1 in symbols: the histogram
For a view with word counts , the histogram is the vector itself. Here for the current view.
Step 2 in symbols: the similarity score
The score between two histograms and is the cosine of the angle between them:
For and , the dot product is and both norms are , so . Real systems weight the words by how informative they are, as in TF-IDF, but the comparison has the same form.
Step 4 in symbols: the geometric check
RANSAC counts the number of matched features that agree with a candidate transformation . Accept the loop only when that count, the inliers, exceeds a threshold. The threshold guards against perceptual aliasing, in which two different places look alike.
Step 5 in symbols: the pose graph
The robot estimates poses by minimising a weighted sum of squared disagreements over all edges:
For the corridor, let the three odometry steps be , each measured as , and let the loop edge say the last pose equals the first, with weight . Write . Then
Setting the derivative with respect to each to zero gives . Summing over the three steps gives , so
With , , and each step is corrected to . The final pose sits at instead of , and the closing gap is .
Worked examples
The robot's current view has histogram . Two stored views are and .
- The norm of the current view is .
- The norm of is .
- The dot product of the current view with is .
- The score is .
- The norm of is . The dot product with the current view is .
- The score is .
Interpretation: is the stronger candidate. The score alone does not prove a loop, which is why step 4 checks the geometry.
Use the corridor from the walkthrough with weight on the loop edge.
- The odometry says each of the three steps is , so the measured poses are .
- The loop edge says the last pose should equal the first, which is .
- Solve for the common correction: .
- Each step becomes . Check: .
- The corrected poses are .
- The cost is . Before the loop edge, the odometry-only cost of the loop edge was .
Interpretation: a single loop edge of equal weight removes most of the drift, but it does not remove all of it, because the odometry still has a say.
A robot drives a 40 m aisle loop. Its wheel odometry overstates distance by 2 percent, a typical scale error for worn wheels on a smooth floor. These numbers are chosen for the calculation.
- The drift at the end of the loop is m. The robot's map puts its final pose 0.8 m past its start, even though it is back where it began.
- Suppose the drift grows evenly, so a pose at distance along the aisle is off by .
- A loop edge at the start is detected from the shelf labels. It pins the first pose and the last pose together.
- Optimising the graph spreads the 0.8 m correction across the trajectory, so a pose at 20 m moves by about 0.4 m and the end pose moves by 0.8 m.
- After correction, the robot's map of the aisle no longer shows a seam where the start and end meet.
Try it: with the loop edge weight and three steps as above, the closing gap is . How large must be for the gap to fall below ? Answer: means , so . A loop edge trusted about ten times as much as each odometry edge is needed to remove almost all of the gap in this toy case.
Common mistakes and tradeoffs
It is tempting to think that any image match is a loop. In fact corridors, shelves and office floors look alike, so two different places can produce a strong histogram match. This is perceptual aliasing, and the geometric check in step 4 exists to reject it. A wrong loop edge can distort the whole map, which is worse than a missed loop.
It is tempting to think that closing a loop fixes the trajectory with one edge. In fact the fix comes from optimising the whole graph, and the weight on the loop edge decides how much of the drift it removes. The toy example shows that equal weights leave a visible gap.
It is also tempting to use the most recent frames as candidates. In fact they always look similar, so they must be excluded, or the robot will report a loop every time it stands still.
Loop closure is worth its cost when the trajectory is long and the robot revisits places, as in mapping a building or driving a city. It is not needed for a short trajectory that never returns, and a robot with reliable absolute positioning may not need it. The main alternatives are place recognition with learned descriptors, which can be more robust to lighting changes, and laser-based loop closure, which avoids the appearance problem entirely.
History
Early mobile-robot mapping treated position as a Gaussian estimate that was updated as the robot moved. Work in the mid-1980s by Smith, Self and Cheeseman on the representation of spatial uncertainty showed how to track a map and a pose together, but the uncertainty grew quickly, and returning to an old place was hard to exploit.
Pose graphs made loops practical. Lu and Milios's 1997 work on globally consistent range-scan alignment showed how to correct a whole trajectory once a loop was found, by treating each measurement as a constraint in one least-squares problem.
Recognising places from images caught on in the late 2000s. Cummins and Newman's FAB-MAP in 2008 used a probabilistic bag-of-words model to detect loops in long image sequences, and Gálvez-López and Tardós's 2012 work on binary words made the search fast enough for real-time systems. Systems such as ORB-SLAM build on this line, which is why the bag-of-words lesson comes first.
Recap
- Loop closure matches the current view against stored views, so the robot can tell that it has returned to a place.
- Matches are scored with a similarity measure, filtered for recency, and then checked geometrically with feature matching and RANSAC.
- An accepted match becomes a loop edge in the pose graph.
- Optimising the pose graph spreads the correction over the trajectory, and the weight on the loop edge sets how much of the drift it removes.
- Read next: Visual SLAM, which combines loop closure with tracking, and Factor Graph, the structure in which the pose graph sits.
Check yourself
QuestionRecall: what does a loop closure edge tell the pose graph?Show answer
It says that two poses that are far apart in time describe the same place in the world, so their estimated positions should agree once the transformation between them is accounted for. The edge carries a weight that reflects how much the robot trusts the match.
QuestionComputation: what is the cosine similarity between the histograms and ?Show answer
The dot product is . Both norms are , so the similarity is .
QuestionWhy: why must a histogram match be followed by a geometric check?Show answer
Two different places can contain the same visual words in similar proportions, for example two identical-looking corridors. A geometric check with feature matching and RANSAC asks whether the matched features agree with a single consistent transformation, which a coincidental look-alike rarely does.
QuestionApplied: with the loop edge weight set to and three odometry steps, what is the closing gap, and what happens to the gap if the loop edge weight is raised?Show answer
The closing gap is . Raising the weight makes the gap smaller, because the optimiser gives more importance to the loop constraint and less to the drifting odometry, so the correction pulls the endpoint harder toward the start.