๐ฏ Object Detection & Tracking โ CodeAlpha Task 4
CodeAlpha AI Internship ยท Task 4
Real-time object detection and tracking using YOLO26 + ByteTrack
Demo
๐ฌ Supports: webcam ยท video file ยท HTTP/RTSP stream ยท YouTube URL
Overview
Real-time object detection and multi-object tracking pipeline built on YOLO26 (Ultralytics, January 2026) and ByteTrack.
Each detected object receives a persistent tracking ID that stays consistent across frames, with a motion trail drawn to visualize its path. The terminal displays a live stats table (classes, counts, active IDs, FPS) using Rich.
How it works
Video frame (webcam / file / stream)
โ
โผ
YOLO26 detection
(single forward pass โ bounding boxes + class labels + confidence)
โ
โผ
ByteTrack
(IoU matching + Kalman filter โ persistent track IDs across frames)
โ
โผ
draw_detections()
(bounding box + label + #ID + motion trail per object)
โ
โผ
OpenCV window (real-time display) + optional .mp4 save
YOLO26
YOLO26 (released January 2026) is the latest Ultralytics model. It introduces:
- NMS-free end-to-end inference โ no Non-Maximum Suppression post-processing
- DFL-free head โ lighter detection head, faster on CPU and edge devices
- 43% faster CPU inference vs YOLO11 nano
ByteTrack
ByteTrack associates YOLO detections across frames using IoU (Intersection over Union) and a Kalman filter for position prediction. It uses both high- and low-confidence detections for matching, recovering tracks during partial occlusions.
Motion trails
Each tracked object leaves a colored trail showing its last 30 positions. The trail fades from bright (recent) to dim (older), giving an immediate visual sense of direction and speed.
Project Structure
CodeAlpha_Object_Detection/
โโโ detect.py โ main CLI script
โโโ requirements.txt
โโโ .gitignore
โโโ README.md
Model weights (.pt) are not committed โ they download automatically from Ultralytics on first run.
Quickstart
Install
git clone https://github.com/Tahsine/CodeAlpha_Object_Detection
cd CodeAlpha_Object_Detection
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
Run
# Webcam (default)
python detect.py --source 0
# Video file + save annotated output
python detect.py --source video.mp4 --save
# HTTP / RTSP stream
python detect.py --source rtsp://192.168.1.1/stream
# YouTube URL (requires yt-dlp โ already in requirements.txt)
python detect.py --source "https://youtu.be/..." --youtube
# Switch tracker
python detect.py --source 0 --tracker botsort
Options
| Argument |
Default |
Description |
--source |
0 |
Input: webcam index, video path, HTTP/RTSP URL |
--model |
yolo26s.pt |
YOLO26 model size: n โ s โ m โ l โ x |
--tracker |
bytetrack |
Tracker: bytetrack (fast) or botsort (robust) |
--conf |
0.25 |
Detection confidence threshold |
--iou |
0.45 |
IoU threshold |
--device |
cpu |
Device: cpu, 0 (GPU), 0,1 (multi-GPU) |
--save |
False |
Save annotated video to output/detected.mp4 |
--output |
output/detected.mp4 |
Output path (used with --save) |
--youtube |
False |
Extract stream URL from YouTube (requires yt-dlp) |
Model sizes
| Model |
Size |
mAP COCO |
Speed CPU |
Use case |
yolo26n.pt |
5MB |
40.9 |
Fastest |
Edge / demo |
yolo26s.pt |
19MB |
48.2 |
Fast |
Default |
yolo26m.pt |
50MB |
52.1 |
Moderate |
Better accuracy |
yolo26l.pt |
90MB |
54.8 |
Slow |
High accuracy |
yolo26x.pt |
130MB |
57.5 |
Slowest |
Maximum accuracy |
Tracker comparison
|
ByteTrack |
BoT-SORT |
| Speed |
โ
Faster |
โ ๏ธ ~30% slower |
| Occlusion handling |
Good |
Better (appearance features) |
| Best for |
Open scenes, traffic |
Crowds, overlapping objects |
Terminal UI
The terminal displays a live Rich panel updated every frame:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ ๐ฏ YOLO26 Object Detection & Tracking โ
โ Model : yolo26s.pt โ
โ Source : video.mp4 โ
โ Tracker : bytetrack โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โโโโโโโโโโโโฌโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ
โ Class โ Count โ Track IDs โ
โโโโโโโโโโโโผโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโค
โ car โ 9 โ #1, #2, #3 ... +6 โ
โ person โ 2 โ #10, #11 โ
โโโโโโโโโโโโดโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโ
Frame: 388 โ FPS: 7.5 โ Active tracks: 11
Dependencies
| Package |
Role |
ultralytics |
YOLO26 model + ByteTrack/BoT-SORT tracking |
opencv-python |
Video capture, frame processing, display |
rich |
Live terminal stats table and panels |
yt-dlp |
Extract direct stream URL from YouTube |
torch / torchvision |
Deep learning backend |
License
MIT