A production-quality Computer Vision detection program built with Python, OpenCV, and YOLOv8, capable of detecting 80+ object classes in real time from a webcam, video file, or image.
This project was built to demonstrate expertise in computer vision detection pipelines — a core skill for AI engineering roles.
- ⚡ Real-time detection from webcam or video file at smooth FPS
- 🎯 YOLOv8 nano model — fast inference, small footprint (~6 MB)
- 📦 Detects 80 COCO classes (vehicles, people, animals, objects)
- 🎨 Per-class colour-coded bounding boxes with confidence scores
- 📊 Live FPS counter and detection count HUD overlay
- 🖼️ Image mode — saves annotated output to disk
- 🔧 Uses C++-backed OpenCV routines for high-performance frame processing
| Layer | Technology |
|---|---|
| Language | Python 3.10+ |
| Computer Vision | OpenCV (cv2) |
| Detection Model | YOLOv8 (Ultralytics) |
| Numerical Processing | NumPy |
| Backend (OpenCV core) | C++ |
# 1. Install dependencies
pip install -r requirements.txt
# 2. Run on live webcam (default)
python detect.py
# 3. Run on a video file
python detect.py --source path/to/video.mp4
# 4. Run on a static image
python detect.py --source path/to/image.jpgNote: The YOLOv8 nano model (
yolov8n.pt, ~6 MB) downloads automatically on first run.
object-detection/
├── detect.py # Main detection script
├── requirements.txt # Dependencies
└── README.md # This file
- Model Load: YOLOv8 is loaded via the Ultralytics API (a high-level wrapper over the C++-optimized PyTorch backend).
- Frame Capture: OpenCV's
VideoCapture(a C++-backed binding) reads frames from the webcam or video file. - Inference: Each frame is passed to the YOLO model, which returns bounding boxes, class IDs, and confidence scores.
- Annotation: Custom
draw_detection()usescv2.rectangle()andcv2.putText()to render results. - HUD: FPS is calculated using
time.perf_counter()and overlaid with a semi-transparent background for readability.