ROB-330 · Lesson 11 of 12 · 32 min

Tracking and 6-D pose estimation

Detection answers 'what is where in this frame'. Robots usually need more: the full position and orientation of an object in 3-D, its six-dimensional (6-D) pose, so a gripper can approach it at the right angle; and a consistent identity over time, so the robot knows the box it saw a moment ago is the same box now, and where it is heading. This lesson covers the tools for both: fiducial markers, which make pose estimation easy and reliable; the perspective-n-point problem, which computes pose from known 3-D points and their images; model- and learning-based pose estimation for ordinary objects; and multi-object tracking, which links detections across frames using the filters of ROB-310.

Fiducial markers

The most reliable way to get a camera pose in a structured environment is to put a known pattern there. Fiducial markers such as ArUco and AprilTag are black-and-white squares with a thick border and an internal binary code. Detection finds square outlines (quadrilaterals) in the image, reads the bit pattern inside, and checks it against a dictionary designed so that codes differ in many bits, giving error detection and a unique ID for each marker. Because the marker's four corners have precisely known positions on a square of side s, they give the 2-D to 3-D correspondences needed to compute the camera's pose relative to the marker in a few milliseconds.

Robots use markers to dock at chargers, to mark pick locations and shelves, to calibrate cameras and hand-eye transforms (lesson 3), to provide ground truth for testing other perception, and to localize in warehouses where a grid of ceiling or floor markers gives absolute position. The AprilTag family (from the University of Michigan) and ArUco (built into OpenCV) are both widely used, and boards of many markers give more accurate and robust poses than a single tag.

Worked problem

How far away can a marker be read?

A 6 × 6-bit ArUco marker with a one-bit border is 8 bits across and 120 mm wide. The camera has \( f_x = 900 \) px. Detectors need roughly 3 pixels per bit to read the code reliably. What is the maximum reading distance?

Show solution
  1. Marker width needed in the image: \( 8 \times 3 = 24 \) px.
  2. Image width at distance Z: \( f_x s/Z = 900 \times 0.120/Z \).
  3. Set equal to 24: \( Z = 900 \times 0.120/24 = 4.5 \) m.

Answer: About 4.5 m. To read markers at 9 m, double the marker size or the focal length. Pose accuracy degrades well before the reading limit, so pose-critical tasks should use markers much larger in the image.

The perspective-n-point problem

Given n known 3-D points \( \mathbf{X}_j \) in an object's frame and their measured image points \( \mathbf{u}_j \), with known intrinsics K, the perspective-n-point (PnP) problem finds the rotation R and translation t that place the object relative to the camera so that the points project where they were observed. It is calibration's mirror image: there the camera parameters were unknown, here only the pose is. Three points give up to four solutions (the P3P problem), so at least four are used in practice to pick the right one; for coplanar points, such as a marker's corners, specialized solvers like IPPE exploit the plane. Efficient general solvers such as EPnP handle any number of points in linear time. As always, robust estimation with RANSAC (lesson 5) rejects bad correspondences, and a final Levenberg–Marquardt refinement minimizes reprojection error:

\[\min_{R,\,\mathbf{t}} \sum_{j=1}^{n} \left\| \mathbf{u}_j - \pi\left(K (R\mathbf{X}_j + \mathbf{t})\right) \right\|^2\]

PnP is used everywhere: for marker poses, for camera localization against a 3-D map in visual odometry and SLAM (lesson 7), and for object poses once a network has predicted where an object's known keypoints appear in the image.

Pose of a square marker from its four corners: a linear homography estimate, then Gauss-Newton refinement of the reprojection error
import numpy as np
rng = np.random.default_rng(21)

K = np.array([[900.0, 0, 640], [0, 900.0, 360], [0, 0, 1]])
s = 0.12                                              # marker side, m
obj = np.array([[-s/2, s/2], [s/2, s/2], [s/2, -s/2], [-s/2, -s/2]])   # corners in marker plane (z = 0)

def rot(rx, ry, rz):
    cx, sx, cy, sy, cz, sz = np.cos(rx), np.sin(rx), np.cos(ry), np.sin(ry), np.cos(rz), np.sin(rz)
    Rx = np.array([[1, 0, 0], [0, cx, -sx], [0, sx, cx]])
    Ry = np.array([[cy, 0, sy], [0, 1, 0], [-sy, 0, cy]])
    Rz = np.array([[cz, -sz, 0], [sz, cz, 0], [0, 0, 1]])
    return Rz @ Ry @ Rx

R_true = rot(np.deg2rad(25), np.deg2rad(-15), np.deg2rad(10)); t_true = np.array([0.10, -0.05, 1.50])
P3 = np.column_stack([obj, np.zeros(4)])
img = (K @ (R_true @ P3.T + t_true[:, None])).T
img = img[:, :2] / img[:, 2:] + rng.normal(0, 0.3, (4, 2))          # 0.3 px corner noise

# planar pose: homography from marker plane to image, then H = K [r1 r2 t] up to scale
A = []
for (X, Y), (u, v) in zip(obj, img):
    A += [[X, Y, 1, 0, 0, 0, -u*X, -u*Y, -u], [0, 0, 0, X, Y, 1, -v*X, -v*Y, -v]]
H = np.linalg.svd(np.array(A))[2][-1].reshape(3, 3)
B = np.linalg.inv(K) @ H
lam = 2 / (np.linalg.norm(B[:, 0]) + np.linalg.norm(B[:, 1]))
if B[2, 2] * lam < 0: lam = -lam                      # marker must be in front of the camera
r1, r2, t = lam * B[:, 0], lam * B[:, 1], lam * B[:, 2]
Rm = np.column_stack([r1, r2, np.cross(r1, r2)])
U, _, Vt = np.linalg.svd(Rm); R_est = U @ Vt          # nearest true rotation

def rodrigues(w):
    th = np.linalg.norm(w)
    if th < 1e-12: return np.eye(3)
    k = w / th; Kx = np.array([[0, -k[2], k[1]], [k[2], 0, -k[0]], [-k[1], k[0], 0]])
    return np.eye(3) + np.sin(th) * Kx + (1 - np.cos(th)) * Kx @ Kx

def residual(x):
    R = rodrigues(x[:3]) @ R_est
    q = (K @ (R @ P3.T + x[3:, None])).T
    return (q[:, :2] / q[:, 2:] - img).ravel()

def report(label, R, t):
    ang = np.degrees(np.arccos(np.clip((np.trace(R.T @ R_true) - 1) / 2, -1, 1)))
    q = (K @ (R @ P3.T + t[:, None])).T
    rms = np.sqrt(((q[:, :2] / q[:, 2:] - img) ** 2).sum(1).mean())
    e = 1000 * (t - t_true)
    print("%s: error x %.1f, y %.1f, z %.1f mm; rotation %.2f deg; RMS %.2f px" % (label, e[0], e[1], e[2], ang, rms))

report("homography only", R_est, t)

# Gauss-Newton refinement of reprojection error over a small rotation vector and t
x = np.concatenate([np.zeros(3), t])
for it in range(10):
    r0 = residual(x)
    J = np.column_stack([(residual(x + d) - r0) / 1e-6 for d in np.eye(6) * 1e-6])
    x = x - np.linalg.lstsq(J, r0, rcond=None)[0]
report("after refinement", rodrigues(x[:3]) @ R_est, x[3:])
Output
homography only: error x -3.5, y 2.0, z -46.2 mm; rotation 7.42 deg; RMS 2.19 px
after refinement: error x -0.5, y 0.2, z -3.4 mm; rotation 1.46 deg; RMS 0.25 px

The linear homography solution is only a starting point: it leaves a 46 mm depth error, a 7° rotation error and 2.2 px of reprojection error. Refining by minimizing reprojection error, as every practical PnP solver does, brings the pose to within about 3 mm in depth and 1.5° in rotation, with residuals matching the 0.3 px corner noise. Even after refinement, the error along the viewing direction is several times the sideways error, and tilt is the least certain part of the rotation. Depth and tilt are the weak directions of single-marker pose, which is why marker boards, larger markers and filtering over several frames are used when accuracy matters.

Worked problem

Depth uncertainty from a small marker

A marker 120 mm wide is seen at 1.5 m by a camera with \( f = 900 \) px. Its apparent width is about 72 px. If corner noise makes the measured width uncertain by ±0.5 px, roughly how uncertain is the distance?

Show solution
  1. Distance from apparent width: \( Z = fs/w \), so \( \delta Z/Z = \delta w/w \).
  2. \( \delta Z = 1.5 \times 0.5/72 = 0.0104 \) m.

Answer: About ±10 mm. A marker twice as wide, or seen from half the distance, cuts this to about a quarter, since apparent width and distance both enter.

Pose estimation for ordinary objects

Most objects do not carry markers. Several approaches estimate their 6-D pose, typically for known objects with a CAD model or a set of reference images.

  • Keypoint methods train a network to predict where specific points on the object, such as corners of its 3-D bounding box or distinctive surface points, appear in the image, then solve PnP. PVNet and similar methods vote for each keypoint from many pixels, which tolerates occlusion.
  • Dense correspondence methods predict, for every object pixel, its 3-D coordinate on the model, then solve PnP with RANSAC over thousands of correspondences.
  • Depth-based methods match the observed point cloud against the model, using 3-D descriptors and RANSAC for a coarse pose and ICP for refinement (lesson 8). They excel with good depth and struggle on shiny or dark objects that depth sensors cannot see well.
  • Render-and-compare methods refine a pose by rendering the model at the current estimate and adjusting until the rendering matches the image. Recent model-based foundation methods, such as FoundationPose, at the time of writing, generalize to new objects from a CAD model or a few images without retraining.

Pose accuracy is usually measured with the ADD metric, the average distance between model points transformed by the true and estimated poses, with a pose counted correct if ADD is below 10 % of the object's diameter; symmetric objects such as bottles and bowls use ADD-S, which takes the closest model point, because their pose is ambiguous about the symmetry axis. Symmetry deserves care in practice too: a robot gripping a cylinder does not need its angle about the axis, and forcing a network to predict it only confuses training.

Worked problem

Is the pose good enough to grasp?

A part 150 mm in diameter is estimated with an ADD error of 9 mm. The gripper fingers can tolerate 5 mm of lateral error and 4° of rotation error. The benchmark success criterion is ADD below 10 % of the diameter. Is the pose acceptable by the benchmark, and for the grasp?

Show solution
  1. Benchmark threshold: \( 0.10 \times 150 = 15 \) mm, so 9 mm passes.
  2. The grasp needs 5 mm lateral accuracy, and an average model-point error of 9 mm suggests errors at the grasp points of a similar size.

Answer: It passes the benchmark but probably not the grasp. Application tolerances, not benchmark thresholds, decide whether to grasp, refine with ICP or a closer view, or use a compliant gripper.

Multi-object tracking

A robot watching a conveyor, a crowd or a field of plants must link detections over time into tracks, each with a persistent identity. The standard approach, tracking by detection, runs a detector on every frame and then solves a data association problem.

1. Predict each existing track forward with a motion model, usually a constant-velocity Kalman filter on the box center and size (ROB-310), giving a predicted box and its uncertainty.

2. Compute a cost between every predicted track and every new detection: 1 − IoU, a Mahalanobis distance using the predicted covariance, an appearance distance between learned embeddings, or a combination.

3. Solve the assignment with the Hungarian algorithm, which finds the matching with the lowest total cost, rejecting pairs above a gate.

4. Update matched tracks with their detections, start tentative tracks for unmatched detections, and delete tracks unmatched for too long.

SORT (2016) does this with IoU costs and a Kalman filter; DeepSORT adds an appearance embedding so identities survive occlusions; ByteTrack also associates low-confidence detections in a second pass, recovering objects that a strict threshold would drop. Tracking quality is measured with metrics such as MOTA, IDF1 and HOTA, which count misses, false positives and identity switches.

Two time steps of tracking shown side by side. On the left, three existing tracks with predicted boxes drawn dashed, labeled track 1, 2 and 3, with arrows showing their velocities. On the right, three new detections drawn solid. Lines connect each predicted box to its assigned detection, labeled with costs such as 1 minus IoU equals 0.12, 0.20 and 0.35, and a fourth detection with no match is labeled new track.
Tracking by detection: predicted track boxes are matched to new detections by minimum total cost, and unmatched detections start new tracks

Worked problem

Assigning detections to tracks

Two tracks A and B and two detections 1 and 2 have costs (1 − IoU): A–1 = 0.2, A–2 = 0.7, B–1 = 0.3, B–2 = 0.9. Which assignment minimizes the total cost? What would a greedy method that matches the lowest cost first do?

Show solution
  1. Option 1: A–1 and B–2: \( 0.2 + 0.9 = 1.1 \).
  2. Option 2: A–2 and B–1: \( 0.7 + 0.3 = 1.0 \).
  3. Greedy picks A–1 first (0.2), forcing B–2 (0.9): total 1.1.

Answer: The optimal assignment is A–2 and B–1 with total cost 1.0, which the Hungarian algorithm finds. Greedy matching chooses the worse pairing here, although with a gate of 0.8, B–2 would be rejected and B left unmatched.

Tracking and pose together

In manipulation, tracking and pose estimation combine: a robot picking moving parts from a conveyor estimates each part's pose once with care, then tracks it with a cheap motion model (the conveyor's known speed from an encoder) and refines the pose with fast local updates, rather than solving from scratch every frame. Fusing the camera's pose estimates with a motion model in a Kalman filter also smooths jitter and lets the robot predict where the part will be when the gripper arrives, compensating for perception and planning latency (ROB-320).

Common mistakes

  • MistakeUsing markers so small in the image that their pose is unreliable

    InsteadSize markers for pose accuracy, not just readability, and use marker boards where possible.

  • MistakeSolving PnP with only three points

    InsteadUse four or more points, RANSAC and a final refinement to resolve ambiguity and reject outliers.

  • MistakeTrusting a single-marker pose equally in all directions

    InsteadExpect depth and tilt to be the least accurate and fuse several observations or markers.

  • MistakeJudging a pose estimate only against benchmark ADD thresholds

    InsteadCompare errors with the actual tolerances of the grasp or task.

  • MistakeAssociating tracks to detections greedily with no gating

    InsteadUse the Hungarian algorithm with a cost gate and a motion model.

Summary and key terms

  • 6-D pose is an object's full position and orientation; tracking gives it a consistent identity over time.
  • Fiducial markers such as ArUco and AprilTag give unique IDs and four precise corners for fast pose estimation.
  • PnP finds R and t from known 3-D points and their images, using RANSAC and reprojection-error refinement.
  • Single-marker pose is weakest in depth and tilt; larger markers, boards and fusion improve it.
  • Unmarked objects are posed by keypoints with PnP, dense correspondences, depth-based registration or render-and-compare.
  • ADD and ADD-S measure pose error, but task tolerances decide whether a pose is good enough.
  • Tracking by detection predicts tracks with a Kalman filter and assigns detections with the Hungarian algorithm.
6-D pose
The three position and three orientation parameters of an object.
Fiducial marker
A designed pattern, such as an ArUco or AprilTag marker, placed for reliable detection.
PnP
Perspective-n-point: finding pose from known 3-D points and their image projections.
P3P
The minimal three-point version of PnP, with up to four solutions.
ADD
Average distance between model points under the true and estimated poses.
ADD-S
A symmetric version of ADD using closest model points.
Tracking by detection
Building tracks by associating per-frame detections over time.
Data association
Deciding which measurements belong to which tracks.
Hungarian algorithm
An algorithm that finds the minimum-cost one-to-one assignment.
Identity switch
A tracking error where two objects' identities are swapped.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. How many corners does a square marker give for PnP?

    Show answer

    Four.

  2. A 200 mm marker with \( f = 1000 \) px at 4 m: how wide is it in the image?

    Show answer

    50 px.

  3. How many solutions can P3P have?

    Show answer

    Up to four.

  4. In which directions is single-marker pose usually least accurate?

    Show answer

    Depth and tilt.

  5. What threshold does the ADD success criterion commonly use?

    Show answer

    10 % of the object's diameter.

  6. Why does a bottle need ADD-S?

    Show answer

    It is symmetric, so its rotation about the axis is ambiguous.

  7. What motion model does SORT use?

    Show answer

    A constant-velocity Kalman filter.

  8. What does DeepSORT add to SORT?

    Show answer

    An appearance embedding for association.

  9. Which algorithm finds the minimum-cost assignment?

    Show answer

    The Hungarian algorithm.

  10. Name a tracking quality metric.

    Show answer

    MOTA, IDF1 or HOTA.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz