https://github.com/reality361/opencv-object-detection-ui
π Object Detection with OpenCV & YOLO | Interactive UI π―
https://github.com/reality361/opencv-object-detection-ui
object-detection opencv python yolo yolov5
Last synced: about 1 month ago
JSON representation
π Object Detection with OpenCV & YOLO | Interactive UI π―
- Host: GitHub
- URL: https://github.com/reality361/opencv-object-detection-ui
- Owner: Reality361
- License: mit
- Created: 2025-03-13T19:01:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-13T19:14:25.000Z (over 1 year ago)
- Last Synced: 2025-03-13T20:26:37.742Z (over 1 year ago)
- Topics: object-detection, opencv, python, yolo, yolov5
- Language: Python
- Homepage:
- Size: 21.1 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# π Object Detection with OpenCV & YOLO | Interactive UI π―
π **Real-time Object Detection using YOLO and OpenCV** with a **scrollable, interactive UI** for selecting object categories dynamically.
---
## πΈ **Demo**

---
## π― **Project Overview**
This project implements **real-time object detection** using **YOLO (You Only Look Once)** and **OpenCV** in Python. It features:
β
**Deep Learning-based Object Detection (YOLOv4-tiny)**
β
**Customizable Object Selection via UI Buttons**
β
**Scrollable Category Panel** (Supports 80+ object categories)
β
**Optimized UI** (Compact, modern, and business-ready)
β
**Fast and Efficient** (Utilizing OpenCVβs DNN module)
---
## π **Project Structure**
```
opencv-object-detection-ui/
βββ dnn_model/ # YOLO model files
β βββ yolov4-tiny.cfg
β βββ yolov4-tiny.weights
β βββ classes.txt
βββ main4.py # Main object detection script
βββ gui_buttons.py # GUI button system with scrolling support
βββ README.md # Project documentation
```
---
## π οΈ **Installation & Setup**
### πΉ 1. Clone the Repository
```bash
git clone https://github.com/Reality361/opencv-object-detection-ui.git
cd opencv-object-detection-ui
```
### πΉ 2. Install Dependencies
Ensure you have installed dependencies about OpenCV.
π **Dependencies include:**
- `opencv-python`
- `numpy`
### πΉ 3. Download YOLO Weights
The project requires **YOLOv4-tiny pre-trained weights**.
π₯ Download them from: [YOLO Weights](https://github.com/AlexeyAB/darknet/releases)
Place them inside the `dnn_model/` directory:
```
dnn_model/
βββ yolov4-tiny.cfg
βββ yolov4-tiny.weights
βββ classes.txt
```
---
## βΆοΈ **Running the Object Detector**
```bash
python main4.py
```
π **Controls:**
- **Click on buttons** to enable/disable object detection for specific categories.
- **Scroll with the mouse wheel** to navigate the object selection panel.
- **Press `ESC`** to exit.
---
## π **How It Works**
1. **Loads the YOLOv4-tiny model** via OpenCVβs `cv2.dnn_DetectionModel()`.
2. **Reads class labels** from `classes.txt`.
3. **Captures frames from the webcam** and processes them for detection.
4. **Detects objects** based on confidence threshold.
5. **Draws bounding boxes** and labels detected objects.
6. **Users can dynamically select objects** to detect via an interactive UI.
---
## π¨ **UI Features**
- **Scrollable Button Panel** β All object categories fit neatly.
- **Compact Button Layout** β Easy readability & interaction.
- **Smooth Click & Scroll Support** β Optimized for usability.
### **Example Object Categories:**
| Object | Button Color |
|---------|-------------|
| Person | π¦ Blue |
| Car | π₯ Red |
| Dog | π© Green |
| Bottle | πͺ Purple |
---
## ποΈ **How to Add More Object Categories?**
1. **Edit `dnn_model/classes.txt`**
- Add the new object name on a new line.
2. **Modify `initialize_buttons()` in `main4.py`**
- New buttons are automatically added using the categories list.
---
## π **Performance Optimization**
- Convert the model to **ONNX** for OpenCV acceleration:
```bash
python export.py --weights best.pt --include onnx
```
- Run with **GPU acceleration** (if supported):
```python
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
```
---
## π **TODOs & Future Improvements**
β Enhance UI further with dynamic styling
β Add support for **YOLOv5**
β Train a custom model for additional objects
β Optimize for **edge devices** like Raspberry Pi
---
## π **License**
π This project is open-source and available under the **MIT License**.
---
## π¬ **Contact & Support**
π¨βπ» **Maintainer**: [Reality361](https://github.com/Reality361)
π‘ Have questions? Open an [issue](https://github.com/Reality361/opencv-object-detection-ui/issues).
π Enjoyed the project? Give it a β on GitHub!