π Real-time Object Detection using YOLO and OpenCV with a scrollable, interactive UI for selecting object categories dynamically.
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)
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
git clone https://github.com/Reality361/opencv-object-detection-ui.git
cd opencv-object-detection-uiEnsure you have installed dependencies about OpenCV.
π Dependencies include:
opencv-pythonnumpy
The project requires YOLOv4-tiny pre-trained weights.
π₯ Download them from: YOLO Weights
Place them inside the dnn_model/ directory:
dnn_model/
βββ yolov4-tiny.cfg
βββ yolov4-tiny.weights
βββ classes.txt
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
ESCto exit.
- Loads the YOLOv4-tiny model via OpenCVβs
cv2.dnn_DetectionModel(). - Reads class labels from
classes.txt. - Captures frames from the webcam and processes them for detection.
- Detects objects based on confidence threshold.
- Draws bounding boxes and labels detected objects.
- Users can dynamically select objects to detect via an interactive UI.
- Scrollable Button Panel β All object categories fit neatly.
- Compact Button Layout β Easy readability & interaction.
- Smooth Click & Scroll Support β Optimized for usability.
| Object | Button Color |
|---|---|
| Person | π¦ Blue |
| Car | π₯ Red |
| Dog | π© Green |
| Bottle | πͺ Purple |
-
Edit
dnn_model/classes.txt- Add the new object name on a new line.
-
Modify
initialize_buttons()inmain4.py- New buttons are automatically added using the categories list.
- Convert the model to ONNX for OpenCV acceleration:
python export.py --weights best.pt --include onnx
- Run with GPU acceleration (if supported):
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
β Enhance UI further with dynamic styling
β Add support for YOLOv5
β Train a custom model for additional objects
β Optimize for edge devices like Raspberry Pi
π This project is open-source and available under the MIT License.
π¨βπ» Maintainer: Reality361
π‘ Have questions? Open an issue.
π Enjoyed the project? Give it a β on GitHub!
