π Object detection on images using YOLOv5 with OpenCV DNN.
This project demonstrates how to run YOLOv5 models for detecting multiple objects in static images with bounding boxes and class labels. While YOLOv5 supports multiple variants (s, m, l, x), this implementation specifically uses the lightweight YOLOv5s model in ONNX format (yolov5s.onnx) for efficient inference.
- π Detect objects using YOLOv5s ONNX model
- β‘ Powered by OpenCVβs DNN module β no PyTorch needed!
- π§ Based on COCO dataset with 80+ real-world object classes
- π― Adjustable confidence thresholds and NMS filtering
- π‘ Clean modular code using reusable utils
- π· Automatically saves labeled output images
yolov5-object-detection/
β
βββ assets/
β βββ banner.png
β
βββ input/
β βββ street.jpg
β βββ traffic.jpg
β
βββ output/
β βββ street_yolo5.jpg
β βββ traffic_yolo5.jpg
β
βββ model/
β βββ yolov5s.onnx # YOLOv5 small ONNX model (Download from releases)
β βββ DOWNLOAD_INSTRUCTIONS.md # Instructions for downloading model file (.onnx)
β βββ coco.names # Already included in this folder
β
βββ utils/
β βββ utils_yolo5.py # Post-processing and drawing functions
β
βββ yolo5_detection.py # Main script using ONNX model
β
βββ requirements.txt
βββ .gitignore
βββ LICENSE
βββ README.md
-
π¦ Install dependencies:
pip install -r requirements.txt
-
π Run the script:
python yolo5_detection.py
-
πΌοΈ View output:
- Opens a window showing detection results
- Saves
street_yolo5.jpgto theoutput/folder
The YOLOv5s file is large, so it is provided separately in the Releases section of this repository.
Download it from Releases and place it inside the model/ folder.
Included in this repo:
coco.names(class labels)
Download from Releases:
yolov5s.onnx
- This project uses YOLOv5s β the smallest and fastest variant of YOLOv5.
- Easily replace
yolov5s.onnxwithyolov5m.onnx,yolov5l.onnx, etc. - No PyTorch installation is needed β just OpenCV and NumPy.
Sample detection:
| Input Image | YOLOv5 Output |
|---|---|
![]() |
![]() |
MIT License Β© 2025 Heleena Robert.
Youβre free to use, modify, and share with β€οΈ
Heleena Robert
GitHub
Part of a comparative object detection suite by Heleena Robert
See also: YOLOv4, MobileNet-SSD.
For side-by-side comparison of all 4 object detection models, see the comparison repo.


