This demo uses the YOLO (You Only Look Once) model to detect soccer balls in images,videos and real-time webcam feeds. The project is implemented in Python and uses the ultralytics
library for YOLO, along with OpenCV for image processing.
-
env_yolo/
: Virtual environment directory. -
output/
: Directory for output files. -
README.md
: This file. -
requirements.txt
: List of dependencies. -
src/
: Source code directory.cam_test.py
: Script to capture an image from the webcam.soccer_ball.py
: Script to detect soccer balls in images.soccer_ball_cam.py
: Script for real-time soccer ball detection using a webcam.soccer_ball_video.py
: Script to detect soccer balls in videos.soccer_ball_track.py
: Script to track soccer balls in videos using YOLO.soccer_ball_deepsort.py
: Script to track soccer balls in videos using DeepSort.
-
yolo*.pt
: YOLO model files.
tested with
- CUDA Version: 12.6
- Python Version: 3.12.7
-
Clone the repository:
git clone https://github.com/20wiz/yolo_basic cd yolo_basic
-
Create and activate a virtual environment:
python -m venv env_yolo source env_yolo/Scripts/activate # On Windows # source env_yolo/bin/activate # On Unix or MacOS
-
Install the dependencies:
pip install -r requirements.txt
Depending on your GPU driver and CUDA version, you may need to reinstall PyTorch. https://pytorch.org/
-
YOLO model:
yolo*.pt
model file will be downloaded in the root directory of the project.
-
Run the
soccer_ball.py
script:python src/soccer_ball.py
-
Modify the
image_path
variable in the script to point to your image file:image_path = '.\\test1.webp' # Change to your image path
If you do not have a GPU available, you can set the device to CPU in the scripts by modifying the device
variable:
device = 'cpu' # Use CPU
# device = 'cuda:0' # Use GPU if available
-
Run the
soccer_ball_cam.py
script:python src/soccer_ball_cam.py
-
The script will start the webcam and display the real-time detection results. Press 'q' to quit.
-
Run the
soccer_ball_video.py
script:python src/soccer_ball_video.py
-
Modify the
video_path
variable in the script to point to your video file:video_path = 'soccer_1.mp4' # Change to your video path
-
Run the
soccer_ball_track.py
script:python src/soccer_ball_track.py
-
Modify the
video_path
variable in the script to point to your video file:video_path = 'soccer_1.mp4' # Change to your video path
-
Run the
soccer_ball_deepsort.py
script:python src/soccer_ball_deepsort.py
-
Modify the
video_path
variable in the script to point to your video file:video_path = 'soccer_1.mp4' # Change to your video path
This project is licensed under the MIT License.