AI Lesson 86 – Object Tracking | Dataplexa

Lesson 86: Object Tracking

Object tracking is the process of following a detected object as it moves across video frames. While object detection tells us what is present and where it is in a single frame, object tracking focuses on continuity over time.

In most real-world systems, detection and tracking work together. First, objects are detected, then they are tracked frame by frame.

Real-World Connection

Object tracking is used in video surveillance to follow people, in sports analytics to track players, in self-driving cars to monitor nearby vehicles, and in retail analytics to study customer movement.

Any system that analyzes video instead of static images relies heavily on tracking.

What Is Object Tracking?

Object tracking assigns a consistent identity to an object across multiple frames in a video. Even if the object moves, changes direction, or partially disappears, the tracker tries to keep following it.

  • Works on video streams
  • Tracks object position over time
  • Maintains object identity

Detection vs Tracking

Understanding the difference is important:

  • Object Detection: Finds objects in a single frame
  • Object Tracking: Follows objects across frames

Tracking is usually faster than detection because it does not re-detect objects in every frame.

How Object Tracking Works

Most tracking systems follow this workflow:

  • Detect objects in the first frame
  • Initialize a tracker for each object
  • Update object positions in subsequent frames
  • Re-detect if tracking fails

Popular Object Tracking Algorithms

  • CSRT: Accurate, slower
  • KCF: Faster, less accurate
  • MOSSE: Very fast, basic
  • SORT / Deep SORT: Tracking with identity preservation

Simple Object Tracking Example

Below is a basic example of tracking an object using OpenCV’s CSRT tracker.


import cv2

cap = cv2.VideoCapture("video.mp4")

ret, frame = cap.read()
bbox = cv2.selectROI("Select Object", frame, False)

tracker = cv2.TrackerCSRT_create()
tracker.init(frame, bbox)

while True:
    ret, frame = cap.read()
    if not ret:
        break

    success, box = tracker.update(frame)

    if success:
        x, y, w, h = map(int, box)
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

    cv2.imshow("Object Tracking", frame)
    if cv2.waitKey(30) & 0xFF == 27:
        break

cap.release()
cv2.destroyAllWindows()
  

What This Code Is Doing

The program allows you to select an object in the first frame. Once selected, the tracker follows that object throughout the video.

Instead of re-detecting the object, the tracker predicts its new position in each frame.

Understanding the Output

The output video shows a bounding box that moves along with the selected object. As long as the object remains visible, the tracker maintains its position.

If the object moves too fast or becomes hidden, tracking may fail.

Challenges in Object Tracking

  • Occlusion (object temporarily hidden)
  • Lighting changes
  • Fast motion
  • Multiple similar objects

Why Object Tracking Matters in AI

Tracking allows machines to understand motion and behavior over time. It is essential for video analytics, robotics, and autonomous navigation.

Modern AI systems often combine detection, tracking, and prediction for better accuracy.

Practice Questions

Practice 1: Object tracking is mainly used on images or video?



Practice 2: What follows an object across multiple frames?



Practice 3: Name a tracking algorithm known for accuracy.



Quick Quiz

Quiz 1: What follows an object over time?





Quiz 2: What does tracking try to preserve?





Quiz 3: Which library provides CSRT tracker?





Coming up next: Image Segmentation — dividing images into meaningful regions.