This repository contains a Python script for object counting using the YOLO (You Only Look Once) object detection model implemented in the ultralytics
library along with OpenCV.
Before running the script, ensure you have the following dependencies installed:
- Python (>= 3.6)
- OpenCV (>= 4.5.1)
- Ultralytics (>= 0.0.7)
-
Clone this repository:
git clone https://github.com/PandaMcGame/ML-People-Counter.git cd ml-people-counter
-
Install the required Python dependencies:
pip install -r requirements.txt
-
Download the YOLOv8n pre-trained weights file (
yolov8n.pt
) from here and place it in the root directory of the repository.
Run the following command to execute the object counting script:
python app.py
The provided Python script (app.py
) performs object counting on either a video file (assets/video.mp4
) or live camera feed. Here's a brief overview of the script:
- Imports necessary libraries:
YOLO
fromultralytics
,object_counter
fromultralytics.solutions
, andcv2
from OpenCV. - Initializes the YOLO model with the pre-trained weights (
yolov8n.pt
). - Sets up the video capture from either a video file or camera.
- Defines line points for counting objects.
- Initializes the video writer to save the output.
- Initializes the object counter with specified arguments.
- Starts the main loop for processing video frames:
- Reads frames from the video.
- Detects and tracks objects using the YOLO model.
- Performs object counting and draws bounding boxes and tracks on the frames.
- Writes the annotated frames to the output video file.
- Releases video resources and closes windows.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to modify and use this script according to your requirements! If you have any questions or suggestions, please open an issue or contact the repository owner.