This script analyzes a video using the YOLOv8 model with built-in object tracking, detects people, and prints the total number of unique individuals identified by their unique tracking IDs.
Ideal for applications like crowd counting, person tracking, or video analytics.
Make sure to install the required library:
pip install ultralytics
ultralytics
: provides the YOLOv8 model and tracking tools.
yolo-person-tracking/
β
βββ yolov8s.pt # Pre-trained YOLOv8 model (optional, can be downloaded automatically)
βββ sample.mp4 # Input video to analyze
βββ track_people.py # Main tracking script
- Download your input video and name it
sample.mp4
. - Place it in the same folder as the script.
- If you don't have the
yolov8s.pt
model, download it from: π https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt
Note: You can use
YOLO("yolov8s")
instead to automatically download the model on first run.
Run the script using:
python track_people.py
The script:
- Displays the video with bounding boxes and tracking IDs in real-time.
- Prints the total number of unique people detected during the video.
Example output:
Unique people found in the video: 5
- Lightweight and fast.
- No web interface or server needed.
- Ideal for quick testing or integration into other projects.
- Tracking is handled internally by YOLO using ByteTrack.
- For best results, avoid overly crowded scenes or fast camera movements.
- You can extend this code to export data to CSV, draw counts on screen, or save processed frames.