YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
πͺ Helmet Detection using YOLOv8
This project detects whether riders are wearing helmets using a pre-trained YOLOv8 model. It can process both videos and real-time webcam feeds to identify helmet usage among bikers. The output video is saved with detection boxes labeled as "Helmet" or "No Helmet".
πΈ Demo
Example detection results on bikers --- showing bounding boxes for
helmet and no helmet riders.
Without Helmet
With Helmet
π Features
- Detects helmet and no helmet on motorbike riders.
- Works with video files or live webcam.
- Saves output video automatically.
- Uses a pre-trained model from Hugging Face.
π§ Model Details
- Model Type:
YOLOv8 - Source: Hugging Face ---
sharathhhhh/safetyHelmet-detection-yolov8 - Framework:
Ultralytics YOLOv8 - Format:
.pt(PyTorch weights) - Task: Object Detection
π§° Setup Instructions (Google Colab)
1. Install Dependencies
!pip install ultralytics
2. Mount Google Drive
from google.colab import drive
drive.mount('/content/drive')
3. Import YOLO
from ultralytics import YOLO
4. Load and Run the Model on Video
model = YOLO('/content/drive/MyDrive/safetyHelmet.pt')
results = model.predict(
source='/content/drive/MyDrive/helmet_test.mp4',
conf=0.4,
save=True,
project='/content/drive/MyDrive/',
name='helmet_output'
)
The output video will be saved in
/content/drive/MyDrive/helmet_output/.
5. View Output Video Inline
from IPython.display import HTML
from base64 import b64encode
mp4 = open('/content/drive/MyDrive/helmet_output/helmet_test.mp4','rb').read()
data_url = "data:video/mp4;base64," + b64encode(mp4).decode()
HTML(f'<video width=700 controls><source src="{data_url}" type="video/mp4"></video>')
π₯οΈ Real-time Detection (Optional)
To use your webcam in Colab or a local Python script:
import cv2
from ultralytics import YOLO
model = YOLO('/content/drive/MyDrive/safetyHelmet.pt')
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
results = model(frame)
annotated_frame = results[0].plot()
cv2.imshow("Helmet Detection", annotated_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
π¦ Folder Structure
π Helmet-Detection-YOLOv8
β£ π README.md
β£ π safetyHelmet.pt
β£ π helmet_test.mp4
β£ π detect_helmet.py
β π helmet_output/
π§βπ» Author
Fatima Noor
BSCS Graduate | AI/ML Enthusiast | Computer Vision Developer
This project is open-source and available for educational and research purposes.