This project provides a desktop application for real-time object detection using the YOLOv8 model. It allows users to utilize their laptop camera or upload images to detect objects, presenting the results in a separate, easily manageable window.
- Real-time Object Detection: Leverages YOLOv8 for fast and accurate object detection.
- Camera Integration: Integrates with the user's camera for live object detection. Start/stop camera and toggle realtime detection. Capture and detect the current frame.
- Image Upload Support: Supports loading single or multiple images for detection.
- Results Window: Displays detection results in a table format with Class, Confidence, and bounding box coordinates (x1, y1, x2, y2).
- CSV Export (Optional): Allows exporting detection results to a CSV file for further analysis.
- User-Friendly GUI: Developed using Tkinter, providing an intuitive and easy-to-use interface.
Before running the application, ensure the following are installed:
-
Python: Version 3.6 or higher is recommended.
-
pip: Python package installer.
-
Required Python Libraries:
ultralytics: YOLOv8 libraryopencv-python: For image and video processing.Pillow (PIL): Python Imaging Library for image handling.tkinter: Standard Python GUI library (usually included with Python).numpy: For numerical computations.
-
Clone the Repository:
git clone https://github.com/priyanshubarai/YOLO_app.git cd YOLO_app -
Install Dependencies:
It's highly recommended to create a virtual environment to avoid conflicts with other Python projects.
python -m venv venv source venv/bin/activate # On Linux/macOS venv\Scripts\activate # On Windows
Then, install the required libraries using pip:
pip install ultralytics opencv-python Pillow numpy
-
Download YOLOv8 weights:
Ensure that the
best.ptfile (pretrained YOLOv8 weights) is located in the root directory of the project. If you don't have it:- You will need to train your own model and save it as
best.pt. Refer to the Ultralytics YOLOv8 documentation for instructions. - Alternatively, download a pre-trained model. The instructions on how to do that are not specified in the original documentation.
- You will need to train your own model and save it as
-
Run the Application:
Navigate to the project directory and run the
gui/main_window.pyscript:python main.py
-
Using the GUI:
- Camera Tab:
- Click "Start Camera" to initiate the camera feed.
- Toggle "Realtime Detection" to enable or disable object detection on the live feed.
- Click "Capture and Detect" to capture a single frame and perform object detection.
- Upload Tab:
- Click "Upload Image(s)" to select one or multiple images. The selected images will be displayed with bounding boxes around detected objects.
- Results Window:
- The results window will display a table with the class, confidence, and bounding box coordinates of each detected object.
- (Optional) Use the "Export to CSV" button to save the results to a CSV file.
- Camera Tab:
-
Confidence Threshold:
The
detector.pyscript allows adjusting the confidence threshold for object detection:class YOLODetector: def __init__(self, weights_path: str, confidence_threshold: float = 0.25): self.weights_path = weights_path self.confidence_threshold = confidence_threshold ...
Modify the
confidence_thresholdvalue during initialization to control the sensitivity of the detector. Lower values will detect more objects (with potentially lower confidence), while higher values will only detect objects with higher confidence scores. -
YOLOv8 Weights Path:
The path to the YOLOv8 weights file (
best.pt) can be configured in thedetector.pyscript.
We welcome contributions to improve this project! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Implement your changes and ensure they are well-tested.
- Submit a pull request with a clear description of your changes.
Please follow these guidelines when contributing:
- Adhere to the existing code style.
- Write clear and concise commit messages.
- Provide tests for any new functionality.
This project has no license specified. All rights are reserved.
- Ultralytics for the YOLOv8 framework.
- The OpenCV community for providing excellent image and video processing tools.
- The Python community for creating a powerful and versatile programming language.