This is a Python script that uses the YOLO (You Only Look Once) object detection algorithm to detect various classes of objects in a video or webcam feed. Specifically, it focuses on detecting Personal Protective Equipment (PPE) such as hardhats, masks, safety vests, safety cones, machinery, and vehicles.
This is a Python script that uses the YOLO (You Only Look Once) object detection algorithm to detect various classes of objects related to construction site safety in a video or webcam feed. Specifically, it focuses on detecting Personal Protective Equipment (PPE) such as hardhats, masks, safety vests, safety cones, machinery, and vehicles.
- Python 3.x
ultralytics
librarycv2
(OpenCV) librarycvzone
library- Pre-trained YOLO model file (
ppe-50.pt
) - Video file or webcam for input
- Clone the repository or download the code files.
- Install the required Python libraries using pip:
pip install ultralytics pip install opencv-python pip install cvzone
markdown Copy code
- Download the pre-trained YOLO model file (
ppe-50.pt
) and place it in the same directory as the script.
- Open the script in a Python IDE or text editor.
- Modify the path of the video file or uncomment the webcam-related lines if you want to use the webcam instead.
- Run the script.
The YOLO model used in this project has been trained with fifty epochs using a dataset specifically curated for construction site safety. The training process involved feeding the model with annotated images of construction sites, ensuring the model learns to accurately detect and classify various safety-related objects.
The script will open a window showing the input video or webcam feed. It will draw bounding boxes around the detected objects and display the confidence and class name for each detected object using the cvzone
library.
Feel free to use and modify this code for your own projects.
Nikhil Shendge
- YOLO Algorithm: YOLO: Real-Time Object Detection
ultralytics
library: Ultralytics/YOLOcvzone
library: cvzone- OpenCV Library: OpenCV