A robust helmet detection system using YOLOv8 and YOLOv8-nano models that specifically detect helmets in videos.
- ✅ Helmet-specific detection in videos using specialized models
- ✅ Uses YOLOv8 models (standard and helmet-trained)
- ✅ Pre-trained models (no training required)
- ✅ High accuracy for helmet identification
- ✅ Easy to use with simple commands
-
Clone or download this repository
-
Install Python dependencies:
pip install -r requirements.txt
-
The YOLO models will be automatically downloaded when you first run the script
Using helmet-specific model (Recommended):
python helmet_detector.py --video path/to/your/video.mp4 --model sharathhhhh/safetyHelmet-detection-yolov8Using standard YOLO models:
python helmet_detector.py --video path/to/your/video.mp4# YOLOv8 Small (faster)
python helmet_detector.py --video input.mp4 --model yolov8s.pt
# YOLOv8 Medium (balanced)
python helmet_detector.py --video input.mp4 --model yolov8m.pt
# YOLOv8 Large (best accuracy)
python helmet_detector.py --video input.mp4 --model yolov8l.pt
# YOLOv8 Extra Large (maximum accuracy)
python helmet_detector.py --video input.mp4 --model yolov8x.pt# Lower threshold (detect more objects)
python helmet_detector.py --video input.mp4 --conf 0.20
# Higher threshold (detect only high confidence)
python helmet_detector.py --video input.mp4 --conf 0.40python helmet_detector.py --video input.mp4 --output detected_output.mp4python helmet_detector.py \
--video input.mp4 \
--model yolov8m.pt \
--conf 0.25 \
--output output.mp4| Model | Size | Speed | Accuracy | Use Case |
|---|---|---|---|---|
| YOLOv8n | 6MB | Fastest | Good | Quick processing |
| YOLOv8s | 22MB | Fast | Better | Balanced |
| YOLOv8m | 52MB | Medium | Best Balance | Recommended |
| YOLOv8l | 87MB | Slower | Very Good | High quality |
| YOLOv8x | 136MB | Slowest | Excellent | Maximum quality |
- Python 3.8 or higher
- CUDA-capable GPU (optional, for faster processing)
- 4GB+ RAM
- The script loads a pre-trained YOLO model (YOLOv8)
- Each frame of the input video is analyzed
- The model detects objects including helmets
- Detections are drawn on the video with bounding boxes and confidence scores
- The output video is saved with all detections
yolo/
├── helmet_detector.py # Main detection script
├── requirements.txt # Python dependencies
├── README.md # This file
└── input.mp4 # Your input video (user provided)
- Use a smaller model (yolov8n.pt or yolov8s.pt)
- Lower the input video resolution
- Ensure you have a GPU for faster processing
- Try different YOLO models (larger models have better accuracy)
- Lower the confidence threshold with
--conf 0.20 - Ensure helmets are clearly visible in the video
- Increase the confidence threshold with
--conf 0.40 - Use a larger, more accurate model
- Supported video formats: MP4, AVI, MOV, MKV
- The first run will download the YOLO model automatically
- Processing time depends on video length and model size
- GPU acceleration is used automatically if available
- YOLOv8 by Ultralytics
- OpenCV for video processing