CSC3104 · Module 8 of 9

Video + Tracking

Connect detections across time

~56 min to study properly

Video adds time: a clip is a tensor of shape frames × height × width × channels. Neighbouring frames are very similar, so there's lots of redundancy to exploit.

Checkpoint · the examiner asks

Explain the roles of the Kalman filter and the Hungarian algorithm in SORT. Why was DeepSORT developed?

In one minute

Tracking-by-detection detects objects every frame and links them into tracks. SORT predicts each track's next position with a Kalman filter (constant velocity), builds a cost matrix such as 1 − IoU, and solves it optimally with the Hungarian algorithm. DeepSORT adds a re-ID appearance embedding so identities survive occlusions and crossings.

Traps examiners look for
  • Greedy matching instead of the Hungarian algorithm's optimal one-to-one assignment.
  • Expecting IoU-only matching to keep IDs through occlusion.
  • Confusing optical flow (per-pixel motion) with box tracking.
Read

Study notes

01Video adds time

A video clip is a tensor of shape T × H × W × C (frames × height × width × channels). Neighbouring frames are nearly identical, which is both a burden (lots of redundant data) and a gift (strong continuity to exploit).

Tasks include action recognition (what is happening — often with 3-D convolutions or video transformers over short clips), optical flow (how every pixel moves) and multi-object tracking (MOT) — following each object with a stable identity across frames.

02Tracking-by-detection and the Kalman filter

Most trackers use tracking-by-detection: run a detector on every frame, then link detections into tracks with stable ids.

SORT (Simple Online and Realtime Tracking) does the linking with two tools. First, a Kalman filter per track, with state (position, size, velocity):

  • Predict — move the box forward assuming roughly constant velocity: x̂ = x + v·Δt.
  • Update — when a matching detection arrives, blend prediction and measurement, weighted by their uncertainties.

Prediction lets a track keep moving for a few frames even when its detection is missing (brief occlusion or a missed detection).

03The Hungarian algorithm

Each frame, SORT builds a cost matrix between predicted track boxes (rows) and new detections (columns) — typically cost = 1 − IoU. The Hungarian algorithm finds the optimal one-to-one assignment that minimises total cost (in polynomial time), rather than greedily grabbing the best pair first.

After assignment:

  • matched pairs update their tracks;
  • pairs whose cost is too high (IoU below a gate) are rejected;
  • unmatched detections start new tracks (new ids);
  • unmatched tracks coast on their predictions and are deleted after a maximum age.

04ID switches, DeepSORT and optical flow

With motion and IoU alone, SORT fails when objects cross or are occluded for longer: predictions drift, nothing overlaps on reappearance, and the person gets a new id — an ID switch, the main error MOT metrics count (alongside misses and false positives; see MOTA, IDF1).

DeepSORT adds an appearance embedding from a re-identification CNN trained so that crops of the same person are close in feature space. The cost combines motion (Mahalanobis/IoU) and appearance distance, so a lost track can be re-identified after occlusion.

Optical flow estimates a motion vector for every pixel between two frames (no boxes). Deep models like RAFT compute it accurately; flow is used for motion analysis, video stabilisation and as an input feature for action recognition.

Watch it done

Worked examples

Worked example 1

A Kalman prediction

A track was at x = 180 px moving 14 px/frame. Its detection is missing for 3 frames. Where does the tracker predict it, and what happens if it reappears at x = 214?

    Worked example 2

    Optimal vs greedy matching

    Cost matrix (1 − IoU), tracks T1, T2 vs detections D1, D2: T1→D1 0.2, T1→D2 0.3, T2→D1 0.25, T2→D2 0.9. Compare greedy and Hungarian assignment.

      Vocabulary

      Key terms

      RAFT changed optical flow

      RAFT (ECCV 2020 best paper) builds a 4D correlation volume between all pixel pairs of two frames, then refines a flow field iteratively with a recurrent unit. Its iterative-refinement design influenced later trackers and point-tracking models like CoTracker.

      Practise

      Quick check

      0 of 8 correct so far. Wrong answers come with an explanation — and the buddy can unpack them.

      Q1In SORT, what fills the Hungarian cost matrix?

      Q2Two pedestrians cross and SORT swaps their IDs. DeepSORT's fix?

      Q3What does the Kalman filter's predict step assume in SORT?

      Q4The Hungarian algorithm finds…

      Q5What happens to an unmatched detection in SORT?

      Q6Why did DeepSORT add a re-ID network?

      Q7Optical flow gives…

      Q8x = 50 px, v = 6 px/frame. Prediction after 5 frames?

      Exam-style

      Written practice

      Short answer5 marks

      What does the Hungarian algorithm do in SORT, and why is it preferred to greedy matching?

      Short answer5 marks

      Explain why SORT suffers ID switches and how DeepSORT reduces them.

      Long answer12 marks

      Design a system to count customers entering a supermarket from a ceiling camera without double counting. Describe detection, tracking, the counting logic, how you handle occlusions and crowds, and how you evaluate it.

      Watch

      Videos

      Fresh picks are chosen by AI every day.
      Hands-on

      Kalman prediction & matching

      4 guided tasks: predict, experiment, explain — then challenge yourself. Plus 1 coding exercise you run right in the browser.

      Start the lab