Search

Search papers and lessons

Loop Closure

Level 3 · 11 min read

Loop closure recognises that a robot has returned to a place it has seen before, then uses that match to pull its drifting map back into shape.

On this page

  • Colour = topic mix
  • Linear algebra
  • Probability
  • Calculus
  • Discrete math
  • Inference
  • Signal processing
  • ReadReady to readNot yet

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.

  1. 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 (2,0,1)(2, 0, 1).
  2. 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 P=(2,1,0)P = (2, 1, 0) scores 0.80.8 against the current view, and the stored view Q=(0,1,2)Q = (0, 1, 2) scores 0.40.4. The best candidate is PP.
  3. 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.
  4. 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.
  5. 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]
00.511.522.530123pose indexestimated position
  • odometry only
  • after loop closure
Odometry alone places the last pose at 3. The loop edge pulls it to 0.75, and the correction is spread over the earlier poses.

The math

Definition: Loop closure edge

A loop closure edge is a measurement zijz_{ij} between two poses xix_i and xjx_j 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 wijw_{ij} that says how much the robot trusts it.

Step 1 in symbols: the histogram

For a view with word counts h=(hA,hB,hC)h = (h_A, h_B, h_C), the histogram is the vector itself. Here h=(2,0,1)h = (2, 0, 1) for the current view.

Step 2 in symbols: the similarity score

The score between two histograms uu and vv is the cosine of the angle between them:

s(u,v)=u⋅v∥u∥ ∥v∥.s(u, v) = \frac{u \cdot v}{\|u\|\,\|v\|}.

For u=(2,0,1)u = (2, 0, 1) and v=(2,1,0)v = (2, 1, 0), the dot product is 44 and both norms are 5\sqrt{5}, so s=4/5=0.8s = 4/5 = 0.8. 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 TT. 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 x1,…,xnx_1, \dots, x_n by minimising a weighted sum of squared disagreements over all edges:

C(x)=∑(i,j)wij ∥xj−xi−zij∥2.C(x) = \sum_{(i,j)} w_{ij}\,\bigl\lVert x_j - x_i - z_{ij} \bigr\rVert^2.

For the corridor, let the three odometry steps be d1,d2,d3d_1, d_2, d_3, each measured as 11, and let the loop edge say the last pose equals the first, with weight ww. Write S=d1+d2+d3S = d_1 + d_2 + d_3. Then

C(d)=(d1−1)2+(d2−1)2+(d3−1)2+w S2.C(d) = (d_1 - 1)^2 + (d_2 - 1)^2 + (d_3 - 1)^2 + w\,S^2.

Setting the derivative with respect to each did_i to zero gives di=1−wSd_i = 1 - wS. Summing over the three steps gives S=3−3wSS = 3 - 3wS, so

S=31+3w.S = \frac{3}{1 + 3w}.

With w=1w = 1, S=0.75S = 0.75, and each step is corrected to 0.250.25. The final pose sits at 0.750.75 instead of 33, and the closing gap is 0.750.75.

Worked examples

Example
Scoring two candidate views, hand-computable

The robot's current view has histogram (2,0,1)(2, 0, 1). Two stored views are P=(2,1,0)P = (2, 1, 0) and Q=(0,1,2)Q = (0, 1, 2).

  1. The norm of the current view is 22+02+12=5\sqrt{2^2 + 0^2 + 1^2} = \sqrt{5}.
  2. The norm of PP is 4+1+0=5\sqrt{4 + 1 + 0} = \sqrt{5}.
  3. The dot product of the current view with PP is 2⋅2+0⋅1+1⋅0=42 \cdot 2 + 0 \cdot 1 + 1 \cdot 0 = 4.
  4. The score is 4/(5⋅5)=4/5=0.84 / (\sqrt{5} \cdot \sqrt{5}) = 4/5 = 0.8.
  5. The norm of QQ is 0+1+4=5\sqrt{0 + 1 + 4} = \sqrt{5}. The dot product with the current view is 0+0+1⋅2=20 + 0 + 1 \cdot 2 = 2.
  6. The score is 2/5=0.42/5 = 0.4.

Interpretation: PP is the stronger candidate. The score alone does not prove a loop, which is why step 4 checks the geometry.

Example
Three corridor steps and a loop edge

Use the corridor from the walkthrough with weight w=1w = 1 on the loop edge.

  1. The odometry says each of the three steps is 11, so the measured poses are 0,1,2,30, 1, 2, 3.
  2. The loop edge says the last pose should equal the first, which is 00.
  3. Solve for the common correction: S=3/(1+3⋅1)=0.75S = 3/(1 + 3 \cdot 1) = 0.75.
  4. Each step becomes di=1−S=0.25d_i = 1 - S = 0.25. Check: 3×0.25=0.753 \times 0.25 = 0.75.
  5. The corrected poses are 0,0.25,0.5,0.750, 0.25, 0.5, 0.75.
  6. The cost is 3⋅0.752+0.752=4⋅0.5625=2.253 \cdot 0.75^2 + 0.75^2 = 4 \cdot 0.5625 = 2.25. Before the loop edge, the odometry-only cost of the loop edge was 32=93^2 = 9.

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.

Example
A warehouse aisle with wheel slip, realistic numbers

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.

  1. The drift at the end of the loop is 0.02×40=0.80.02 \times 40 = 0.8 m. The robot's map puts its final pose 0.8 m past its start, even though it is back where it began.
  2. Suppose the drift grows evenly, so a pose at distance ss along the aisle is off by 0.02s0.02 s.
  3. A loop edge at the start is detected from the shelf labels. It pins the first pose and the last pose together.
  4. 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.
  5. 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 ww and three steps as above, the closing gap is 3/(1+3w)3/(1 + 3w). How large must ww be for the gap to fall below 0.10.1? Answer: 3/(1+3w)<0.13/(1 + 3w) \lt 0.1 means 1+3w>301 + 3w \gt 30, so w>9.67w \gt 9.67. 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 (1,0,1)(1, 0, 1) and (1,1,0)(1, 1, 0)?Show answer

The dot product is 1⋅1+0⋅1+1⋅0=11 \cdot 1 + 0 \cdot 1 + 1 \cdot 0 = 1. Both norms are 2\sqrt{2}, so the similarity is 1/(2⋅2)=1/2=0.51 / (\sqrt{2} \cdot \sqrt{2}) = 1/2 = 0.5.

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 w=1w = 1 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 3/(1+3)=0.753/(1 + 3) = 0.75. 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.

Sources