This repository contains a Python script for object detection in images using the YOLOv4 neural network and the OpenCV library. The script loads pre-trained weights and configuration, performs object detection on a given image, and displays the resulting image with the detections drawn.
- Python 3.6+
- pipenv for virtual environment management
- OpenCV
- NumPy
- Matplotlib
To install the dependencies and set up the virtual environment, follow the steps below:
-
Clone this repository:
git clone https://github.com/your-username/yolov4-object-detection.git cd yolov4-object-detection -
Download yolov4 weights on project path:
wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
-
Use
pipenvto create and activate the virtual environment:pipenv install pipenv shell
-
Install the dependencies listed in the
requirements.txtfile:pip install -r requirements.txt
-
Place your input images in the
datafolder. -
Ensure you have the following files in the
cfgfolder:coco.names: File containing the class names.yolov4.cfg: YOLOv4 network configuration file.yolov4.weights: Pre-trained YOLOv4 weights file.
-
Run the main script
main.py:python main.py
βββ cfg
β βββ coco.names
β βββ yolov4.cfg
β βββ yolov4.weights
βββ data
β βββ dog.jpg
β βββ horses.jpg
β βββ humans.jpg
βββ main.py
βββ Pipfile
βββ Pipfile.lock
βββ requirements.txt
βββ README.md
- Loading YOLOv4 network weights and configuration.
- Reading input image.
- Object detection using the YOLOv4 network.
- Displaying the resulting image with bounding boxes and labels of detections.
Contributions are welcome! Feel free to open issues or pull requests for improvements and fixes.
This project is licensed under the MIT License. See the LICENSE file for more information.