Skip to content

About

Real-time object detection, tracking, and per-class counting from a laptop camera (YOLOv8 + supervision/ByteTrack)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Object Detection with Tracking

Status: Work in progress

What it does

Live object detection on a webcam feed using YOLOv8, with unique-object counting powered by ByteTrack. Detected objects are boxed and labeled in real time, and each distinct tracked object is counted once (not once per frame).

Tools used

  • Python
  • OpenCV
  • Ultralytics YOLOv8
  • supervision (ByteTrack for tracking, BoxAnnotator/LabelAnnotator for drawing)

How to run

source cv-env/bin/activate
pip install -r requirements.txt
python3 detect.py

Press q to quit.

Key decision: model size

I tested all five YOLOv8 sizes (n, s, m, l, x) on the same webcam setup and tracked both FPS and tracking stability, not just raw detection accuracy.

Model Speed Tracking stability
yolov8n Fastest, highest FPS Stable counting once tuned
yolov8s Fast, high FPS Stable counting, handles brief occlusion/rotation correctly
yolov8m Noticeably slower Counting instability returns
yolov8l Slower still Counting instability
yolov8x Slowest, lowest FPS Rotating an object causes an immediate recount — tracking breaks

I chose yolov8s. Larger models (m/l/x) are more accurate at classifying similar-looking objects, but their lower FPS hurt tracking specifically: ByteTrack matches objects between frames using box overlap, which assumes objects haven't moved far between frames. Lower FPS means more real time passes between processed frames, so the same object shifts more between frames and overlap-matching fails more often — this shows up as objects getting re-counted as "new" when they briefly rotate, get occluded, or move quickly. At higher FPS (n/s), frames are close together in time, so this problem is far less severe. For a live tracking + counting use case, I prioritized tracking stability over raw classification accuracy, since a wrong-but-stable count is more useful here than an accurate-but-glitchy one.

Key decision: tracker tuning

Default ByteTrack settings caused heavy over-counting — a single stationary person was counted as multiple people due to brief detection flicker being misread as the object disappearing and a new one appearing. I tuned two parameters:

  • lost_track_buffer=90 — gives the tracker more frames to wait before giving up on a temporarily lost object, instead of immediately assigning a new ID.
  • minimum_consecutive_frames=10 — requires an object to be detected consistently for several frames before it's counted at all, filtering out flickery, unstable false detections.

Known limitations

  • The nano/small models sometimes misclassify objects outside their trained 81 categories — for example, my earbuds were detected as "sports ball," a curtain pattern as "broccoli," and a bag/garment as "tie." This is expected: YOLOv8 can only output one of its fixed COCO categories, and picks its closest guess for anything it wasn't trained on. Fixing this would require custom training on my own labeled data, which is a separate future project.
  • Counting reflects unique tracked IDs, not verified unique real-world objects. If an object is briefly hidden, rotated fast, or moves out of the tracker's buffer window, it can be re-counted as a new object. This is inherent to tracking-by-detection and gets worse as model size increases (see model comparison above), since larger/slower models process fewer frames per second and lose continuity more easily.
  • Rotating an object quickly (e.g. turning a phone edge-on) can still cause a recount even on the faster models if the shape change is severe enough to break box-overlap matching, or if the disruption outlasts the tracker's buffer window.

Possible next steps

  • Custom training on objects outside COCO's 80 classes
  • CSV logging of detections with timestamps
  • Confidence-threshold filtering before detections reach the tracker

About

Real-time object detection, tracking, and per-class counting from a laptop camera (YOLOv8 + supervision/ByteTrack)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages