Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 YOLOv5 Object Detection with OpenCV DNN

YOLOv5 Banner

Python OpenCV License: MIT Made with Love By HeleenaRobert


πŸš€ 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.


✨ Key Features

  • πŸš€ 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

πŸ“ Folder Structure

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

▢️ How to Run

  1. πŸ“¦ Install dependencies:

    pip install -r requirements.txt
  2. πŸš€ Run the script:

    python yolo5_detection.py
  3. πŸ–ΌοΈ View output:

    • Opens a window showing detection results
    • Saves street_yolo5.jpg to the output/ folder

πŸ“¦ Model Files

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

πŸ“Œ Notes

  • This project uses YOLOv5s β€” the smallest and fastest variant of YOLOv5.
  • Easily replace yolov5s.onnx with yolov5m.onnx, yolov5l.onnx, etc.
  • No PyTorch installation is needed β€” just OpenCV and NumPy.

πŸ“Š Output Examples

Sample detection:

Input Image YOLOv5 Output
Input Output

🧾 License

MIT License Β© 2025 Heleena Robert.
You’re free to use, modify, and share with ❀️


πŸ‘©β€πŸ’» Author

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.

About

πŸ–ΌοΈ Object detection on images using YOLOv5s (ONNX) with OpenCV DNN. A lightweight, framework-independent implementation for fast and accurate detection.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages