A real-time object detection and tracking application using YOLOv8, OpenCV, and CVZone. This project detects objects from a video feed or webcam and draws bounding boxes with confidence scores around the detected objects.
- Real-Time Object Detection: Uses YOLOv8 for accurate object detection in real-time.
- Object Tracking: Visualizes object bounding boxes and class labels.
- Customizable Classes: Predefined COCO dataset classes.
- Video/Live Feed: Supports webcam or video file inputs.
- Python 3.x
- OpenCV
- Ultralytics YOLOv8
- CVZone
-
Clone the repository:
git clone https://github.com/alihassanml/YOLOv8-ObjectTracker.git cd YOLOv8-ObjectTracker
-
Create and activate a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Download YOLOv8 weights:
Place the YOLOv8 model weights (
yolov8n.pt
) in theweights/
directory.
Run the following command to start object detection with a webcam:
python app.py
You can customize the object detection classes by modifying the classNames
list in the code.
The main components of this project include:
- YOLOv8: Used for object detection.
- OpenCV: To handle video input and display.
- CVZone: For better visualization of bounding boxes and labels.
import os
import cv2
import math
import cvzone
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('weights/yolov8n.pt')
# Predefined COCO classes
classNames = ["person", "bicycle", "car", "motorbike", "aeroplane", ...]
Feel free to submit issues, fork the repository, and make pull requests. Contributions are welcome!
This project is licensed under the MIT License - see the LICENSE file for details.