🗡️ Weapon Detection ML Algorithm
A real-time weapon and threat detection system built with YOLOv8 and OpenCV. Designed to identify weapons and suspicious individuals through live webcam or pre-recorded video footage.
🖼️ Project Sample Images
🎥 Project Demo Video
Weapon Detection Demo
📋 Architecture & Overview
This system implements a custom-trained YOLOv8 object detection model combined with an OpenCV video processing pipeline. Designed around a three-tier threat classification hierarchy, the architecture prioritizes low-latency analysis and false-positive mitigation using object tracking and dynamic thresholding.
🎯 Threat Classification Matrix
| Class | Threat Category | Alert Level | Visual Indicator |
|---|---|---|---|
| 🔫 Gun | High Threat | Critical | Red Banner |
| 🔪 Knife | Active Threat | Warning | Red Banner |
| 🎭 Masked Individual | Suspicious Activity | Caution | Yellow Banner |
⚙️ Technical Highlights
- Multi-Tier Threat Logic: Dynamically categorizes real-time inputs into clear operational states (All Clear, Suspicious, or Critical Threat).
- Object Tracking Integration: Leverages ByteTrack alongside YOLOv8 bounding boxes to maintain consistent tracking IDs and prevent frame-by-frame flickering.
- Confidence Scoring & Thresholding: Filters out marginal detections using custom score validation and counter thresholds to optimize accuracy.
- Optimized Video Pipeline: Built on Python and OpenCV to handle live streams or pre-recorded feeds with minimal execution overhead.
📊 Model Evaluation & Performance
Core Strengths
- Reliable inference on localized webcams and controlled environments.
- Accurate identification of hand-held weapons across varying footages.
- Stable close-to-medium range knife detection and smooth processing throughput.
Limitations & Edge Cases
- Environmental Sensitivity: Detection metrics fluctuate under low-light conditions or poor camera resolutions.
- Distant Scans: Long-range gun identification experiences lower confidence scores due to pixel constraints.
- False Positives: Complex backgrounds occasionally trigger false classifications on similarly-shaped objects.
Validation Test Matrix
| Testing Environment | Gun Detection | Knife Detection | Masked Person |
|---|---|---|---|
| Local Webcam | Operational | Operational | Operational |
| CCTV Feed Simulation | 50% - 60% Confidence | 50% - 60% Confidence | 50% - 60% Confidence |
| Low-Illumination | Degraded | 50% - 60% Confidence | Degraded |
🔧 Technical Stack
| Component | Technology / Framework | Application |
|---|---|---|
| Core Engine | Python 3.13 | Primary programming environment |
| Object Detection | YOLOv8 (Ultralytics) | Real-time bounding box identification |
| Video Processing | OpenCV | Frame capture, manipulation, and rendering |
| Tracking Algorithm | ByteTrack | Multi-object tracking consistency |
| Model Training | Google Colab / Roboflow | Dataset annotation and training pipeline |
🚀 Engineering Roadmap
- [ ] Expand classification taxonomy (baton, taser, and secondary threat vectors)
- [ ] Transition training pipelines to higher-resolution CCTV datasets
- [ ] Implement event logging with automated timestamping
- [ ] Port architecture to edge hardware (e.g., Raspberry Pi)
- [ ] Integrate external warning triggers (audio alarms or API-based notifications)
⚠️ Disclaimer & Discretion
Developed strictly for academic research, prototyping, and engineering portfolio demonstration. Not validated for production deployment in commercial security, public safety, or law enforcement infrastructure.