Sub topic 1
What Multi-Object Tracking Asks For
Multi-object tracking (MOT) takes a video and produces one trajectory per object, with each trajectory keeping the same identity from the object's first appearance to its last. This chapter defines the problem precisely, separates it from detection and single-object tracking, and lists the sources of difficulty that the rest of the tutorial addresses.
Prerequisites
This chapter assumes you know:
- Basic Python and NumPy.
- What an object detector outputs: bounding boxes, class labels, and confidence scores.
- Vectors and matrices at an introductory level.
- What a Gaussian distribution is.
You do not need to know any tracking algorithm yet.
The Problem in One Sentence
Given a sequence of frames, output for every frame a set of boxes, each tagged with an integer ID, so that the same real-world object always gets the same ID and different objects never share one.
The identity requirement is the heart of the task. A detector can tell you there are three people in frame 40 and three people in frame 41. It cannot tell you that the person on the left in frame 40 is the person who moved to the middle in frame 41. A tracker answers that question for every object in every frame.
Detection, Single-Object Tracking, and MOT
MOT sits between two related tasks. The table shows what each one does.
| Task | Input | Output | Identity across frames? | Number of objects |
|---|---|---|---|---|
| Object detection | One image | Boxes, classes, scores | No | Unknown, any number |
| Single-object tracking (SOT) | Video plus the box of one target in frame 1 | The target's box in each frame | Trivial, there is one target | Exactly one, given by the user |
| Multi-object tracking (MOT) | Video | Boxes with IDs in each frame | Yes, the main goal | Unknown, changes over time |
Two differences matter in practice.
- Who chooses the targets. In SOT a person marks the target once, and the tracker follows it. In MOT the system must find targets itself, start tracking them when they appear, and stop when they leave. MOT therefore has to decide how many objects exist at each moment.
- Where the ambiguity comes from. SOT mainly fights appearance change and drift. MOT also has to decide which of several similar-looking objects is which. Two pedestrians in similar clothes crossing paths is an MOT problem that SOT never faces.
Inputs and Outputs
The standard MOT formulation, used by the MOTChallenge benchmarks, has simple data formats.
- Input per frame: a list of detections. Each detection has a box, usually written
[x1, y1, x2, y2], and a confidence score. - Output per frame: a list of tracked boxes, each with an integer track ID.
A track is the full history of one ID: the frames where it appeared and the box in each frame. A trajectory is the same thing viewed as a path through space.
MOTChallenge result files store one row per box: frame number, ID, box left, top, width, height, and a score. Many pipelines write this format directly. The following code parses rows in that format into trajectories and checks that no ID appears twice in the same frame.
from collections import defaultdict
rows = [
# frame, id, left, top, width, height
(1, 1, 10, 10, 40, 40),
(1, 2, 100, 100, 50, 60),
(2, 1, 14, 10, 40, 40),
(2, 2, 103, 102, 50, 60),
(3, 1, 18, 11, 40, 40),
]
trajectories = defaultdict(list)
seen = set()
for frame, track_id, left, top, w, h in rows:
assert (frame, track_id) not in seen, "an ID must appear once per frame"
seen.add((frame, track_id))
center = (left + w / 2, top + h / 2)
trajectories[track_id].append((frame, center))
for track_id, points in sorted(trajectories.items()):
print(track_id, points)The assertion encodes one rule of valid output: an ID can label at most one box in a frame.
What a Correct Answer Looks Like
A perfect tracker satisfies three conditions.
- Every object is found. Each real object in each frame has a tracked box.
- No phantom objects. Each tracked box corresponds to a real object.
- Identities are consistent. Each real object keeps one ID for its whole life, and no two objects share an ID.
The first two are detection quality. The third is what makes tracking a separate problem. Later chapters show that metrics weigh these conditions differently: some emphasize box coverage, others emphasize how long an ID stays correct.
The Pipeline This Tutorial Builds
The dominant approach is tracking-by-detection. A separate detector runs on every frame, and the tracker only links detections over time. This split lets you swap in a better detector without touching the tracker.
The tracker keeps state between frames: where each track was, how fast it was moving, and how long since it was last seen. At each new frame it uses that state to decide which detection belongs to which track. The next chapters build this loop one piece at a time.
Why It Is Hard
If detections were perfect and objects never overlapped, tracking would be trivial. Real video breaks both assumptions.
- Occlusion. An object passes behind another object or a pole. The detector may miss it for several frames, or return a box that covers only part of it. The tracker must decide whether the object left or is hidden.
- Similar appearance. People in uniforms, cars of the same model, and sports players look alike. Position and motion are often the only cues, and they fail when objects cross.
- Unreliable detections. Detectors produce false positives (a box on empty background) and false negatives (a missed object). Blur and low light make both worse.
- Variable object count. Objects enter and leave the scene. A tracker that always expects the same number of objects will fail.
- Camera motion. When the camera pans or shakes, every box moves even if nothing in the world did. Motion predictions based on image coordinates then become wrong.
- Real-time limits. Many uses, such as traffic monitoring or robotics, need the tracker to run at video frame rate. The matching step must be cheap.
Two Kinds of Failure
Tracking errors fall into two groups, and it helps to name them early because evaluation metrics later separate them.
- Detection-type errors: missed objects and false boxes. The tracker output contains the wrong set of boxes.
- Association-type errors: correct boxes with wrong identities. An ID switch happens when one real object's ID changes. A fragmentation happens when a trajectory is broken into pieces by gaps.
The following function counts ID switches given, for each frame, a mapping from real object to the track ID that covers it. It treats a change of ID for the same object as one switch.
def count_id_switches(assignments):
"""assignments: list of dicts, one per frame, mapping object id -> track id."""
last_track_for_object = {}
switches = 0
for frame in assignments:
for obj, track in frame.items():
if obj in last_track_for_object and last_track_for_object[obj] != track:
switches += 1
last_track_for_object[obj] = track
return switches
frames = [
{1: 7, 2: 8},
{1: 7, 2: 8},
{1: 8, 2: 7}, # two people crossed and the tracker swapped their IDs
{1: 8, 2: 7},
]
print(count_id_switches(frames)) # 2A swap during a crossing produces two ID switches, one for each person. Each box in this example is well placed, yet the identities are wrong. That is why a tracker needs its own evaluation beyond detection accuracy.
Online and Offline Tracking
Trackers differ in how much video they may look at.
- Online trackers use only the current and earlier frames. They can run live, but they cannot fix a mistake once an ID has been output.
- Offline (or batch) trackers see the whole video. They can look ahead to decide who emerged from behind an occlusion, which usually gives better identities but rules out live use.
This tutorial focuses on online trackers, because SORT, DeepSORT, and ByteTrack are all online methods.
What You Will Build Next
The following chapters take each piece of the pipeline in turn: what detections look like as input, how to measure box overlap, how to match detections to tracks, how to predict motion, how to manage track lifecycle, and how SORT, DeepSORT, and ByteTrack combine these ideas. The last chapters cover failure modes, metrics, benchmarks, and end-to-end alternatives. Every one of them serves the goal stated here: a consistent ID for every object, in every frame.
Exercise
A detector finds three cars in frame 10 and three cars in frame 11. Why can this output not be used as tracking output, and what extra information must a tracker add?
Show answer
Detections carry no identity. Nothing says which car in frame 11 is which car in frame 10. A tracker must add a consistent ID to each box by linking detections across frames, and must decide when to start new IDs and end old ones.
Exercise
Two pedestrians walk toward each other, cross, and continue. The tracker's boxes fit both people well in every frame, but after the crossing their IDs are swapped. Which kind of error is this, and how many ID switches does it count?
Show answer
It is an association-type error, specifically an ID switch. It counts as two ID switches, one for each person, even though every box is accurately placed.
Exercise
Give two reasons MOT is harder than single-object tracking.
Show answer
Any two of these: the number of objects is unknown and changes as objects enter and leave; the tracker must find targets itself rather than receiving one from the user; several similar objects can be confused with each other; occlusion between objects hides some of them; detection errors add false and missing boxes.