Real-Time Weapon Detection using YOLOv8 β’ Flask β’ OpenCV β’ Raspberry Pi β’ Twilio
- Overview
- Problem Statement
- Solution
- Features
- System Architecture
- Detection Methodology
- Technology Stack
- Hardware Requirements
- Software Requirements
- Project Structure
- Screenshots
- Installation
- Configuration
- Running the Project
- Workflow
- Model Performance
- Security
- Limitations
- Future Roadmap
- Contributing
- License
- Author
FALCON (Automatic Crime Alert and Reporting System) is an AI-powered surveillance and emergency response platform designed to detect dangerous objects such as weapons in real-time using computer vision and deep learning techniques.
The system uses a custom-trained YOLOv8 object detection model to analyze live camera feeds, identify potential threats, capture evidence, store detection records, and automatically notify authorized personnel through Twilio SMS alerts.
Unlike traditional CCTV systems that only record incidents and require continuous human monitoring, FALCON performs automated threat detection and rapid response using Artificial Intelligence.
The system combines:
- Computer Vision
- Deep Learning
- Edge AI Processing
- Real-Time Video Analysis
- Backend Development
- Database Management
- Automated Alert Generation
The project is designed for real-world surveillance applications including smart security systems, public safety monitoring, and emergency response solutions.
Traditional CCTV surveillance systems only provide video recording capabilities.
Although cameras continuously monitor environments, identifying dangerous activities still depends on human operators. This creates several problems:
- Delayed threat identification
- Slow emergency response
- Human monitoring limitations
- Difficulty reviewing large amounts of recorded footage
- Lack of automated incident reporting
In critical situations involving weapons or violent activities, even a few seconds of delay can increase the severity of an incident.
FALCON addresses this challenge by introducing an AI-based automated surveillance system capable of detecting threats, generating alerts, and maintaining digital incident records.
FALCON provides an automated AI surveillance pipeline:
-
Camera captures live video input.
-
OpenCV extracts video frames.
-
YOLOv8 analyzes each frame for weapon detection.
-
Detection results are evaluated using confidence thresholds.
-
When a threat is detected:
- Evidence image is captured
- Detection information is stored
- Incident details are recorded
- Twilio sends SMS alerts
- Dashboard is updated
The system continuously monitors the environment and performs real-time threat detection without requiring constant human supervision.
- Real-time weapon detection using YOLOv8
- Custom-trained object detection model
- Bounding box visualization
- Confidence score calculation
- Image and video evidence capture
- Automated threat identification
- USB camera support
- RTSP/IP camera support
- Live video stream processing
- Frame-by-frame AI analysis
- Raspberry Pi compatible edge deployment
- Instant SMS notification using Twilio API
- Threat detection timestamp
- Detection information sharing
- Emergency response notification
- Web-based monitoring dashboard
- Detection history tracking
- Incident reports
- Captured evidence management
- Detection statistics
- User registration
- Secure login system
- Password encryption
- Session management
- Protected dashboard access
- SQLite database integration
- Detection record storage
- Alert history management
- User information management
- Raspberry Pi compatible architecture
- Local AI inference
- Reduced response latency
- No dependency on cloud processing
- Better privacy and security
IP Camera / USB Camera
β
βΌ
RTSP Video Stream
β
βΌ
OpenCV Frame Capture
β
βΌ
Image Preprocessing
β
βΌ
YOLOv8 Detection Model
β
βΌ
Object + Confidence Analysis
β
βΌ
Threat Decision Logic
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
Capture Evidence Generate Alert
Image / Video Twilio SMS
β β
βΌ βΌ
SQLite Database Emergency Contact
β
βΌ
Flask Web Dashboard
β
βΌ
Reports and Incident History
The complete system works as a continuous AI surveillance loop:
Camera Input β Frame Processing β Object Detection β Threat Analysis β Evidence Storage β Alert Generation β Reporting
The system receives live video input from:
- IP Camera through RTSP protocol
- USB Camera
RTSP provides continuous real-time video transmission with low delay.
OpenCV captures the incoming video stream and converts it into individual frames.
Example:
30 FPS video = 30 individual images processed every second.
Before AI processing:
- Frames are resized
- Pixel values are optimized
- Input format is prepared for YOLOv8
The YOLOv8 model analyzes each frame and identifies possible weapons.
The model returns:
- Object class
- Bounding box coordinates
- Confidence score
Example:
Weapon Detected
Confidence: 92%
The system does not generate alerts for every detection.
A confidence threshold is applied:
Example:
Confidence > 60%
AND
Object = Weapon
Then:
Threat Confirmed
After threat confirmation:
- Detection image is captured
- Bounding box is stored
- Timestamp is recorded
- Incident data is saved
The Flask backend triggers Twilio SMS notification containing:
- Threat information
- Detection time
- Camera information
Detection information is stored in SQLite:
- Date and time
- Detected object
- Confidence score
- Evidence path
| Layer | Technology |
|---|---|
| Programming Language | Python |
| Backend Framework | Flask |
| Frontend | HTML, CSS, JavaScript |
| AI Model | YOLOv8 (Ultralytics) |
| Computer Vision | OpenCV |
| Deep Learning Framework | PyTorch |
| Database | SQLite |
| Camera Streaming | RTSP |
| Alert System | Twilio API |
| Dataset Annotation | Roboflow |
| Hardware Deployment | Raspberry Pi |
| Version Control | Git & GitHub |
Recommended:
- Processor: Intel i5 / Ryzen 5 or above
- RAM: 8GB minimum
- Storage: 10GB+ free space
- Operating System: Windows/Linux
Specifications:
- Raspberry Pi 5
- 8GB RAM
- Camera module/IP Camera
- MicroSD Card
- Power supply
- Network connectivity
Supported:
- USB Camera
- IP Camera
- RTSP-enabled CCTV Camera
- Python 3.10+
- Flask
- OpenCV
- Ultralytics YOLOv8
- PyTorch
- SQLite
- Twilio API
- Git
- Visual Studio Code
FALCON/
β βββ AI/ β β β βββ init.py β βββ yolo_detect.py β βββ live_rtsp_detector.py β βββ train_yolo.py β β β βββ models/ β βββ best.pt β βββ alerts/ β β β βββ init.py β βββ twilio_alert.py β βββ database/ β β β βββ init.py β βββ detection_db.py β βββ alert_db.py β βββ add_users.db β βββ detections.db β βββ alerts.db β βββ media/ β β β βββ output/ β βββ screenshots/ β βββ static/ β βββ templates/ β βββ train_detect_weapons/ β β β βββ data.yaml β βββ dataset/ β βββ app.py βββ config.py βββ run.py βββ requirements.txt βββ .env βββ .gitignore βββ README.md
git clone https://github.com/Astik97/FALCON.git
cd FALCONCreate virtual environment
Windows
python -m venv venvvenv\Scripts\activateLinux
python3 -m venv venvsource venv/bin/activateInstall dependencies
pip install -r requirements.txtCreate a .env file inside the project root directory.
Example:
SECRET_KEY=your_secret_key
MODEL_PATH=AI/models/best.pt
# Twilio Configuration
TWILIO_ACCOUNT_SID=your_account_sid
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_PHONE_NUMBER=your_twilio_number
ALERT_RECEIVER_NUMBER=receiver_numberpython app.pyOpen
http://127.0.0.1:5000
FALCON provides a central launcher using run.py.
Start the system:
python run.py
Start System
β
βΌ
Camera Initialization
β
βΌ
OpenCV Video Capture
β
βΌ
Extract Video Frames
β
βΌ
YOLOv8 Prediction
β
βΌ
Weapon Object Detected?
β β
No Yes
β β
β βΌ
β Capture Evidence
β β
β βΌ
β Save Image/Video
β β
β βΌ
β Store Detection Data
β β
β βΌ
β Twilio SMS Alert
β β
ββββββββββββββββ
β
βΌ
Update Dashboard
β
βΌ
Generate Reports
| Metric | Value |
|---|---|
| Model | YOLOv8 |
| Dataset | Custom Weapon Dataset |
| Annotation Tool | Roboflow |
| Training Framework | Ultralytics |
| Image Size | 640x640 |
| Epochs | 50 |
| Precision | 85% |
| Recall | 75% |
| mAP@0.5 | 81% |
Performance may vary depending on:
- Hardware capability
- Camera quality
- Lighting conditions
- Detection confidence threshold
- Model optimization
| Device | FPS | Latency | Expected Capability |
|---|---|---|---|
| GPU System | 15β25 | 40β60 ms | Faster YOLO inference |
| Desktop CPU | 5β10 | 120β200 ms | Development and testing |
| Raspberry Pi | 1β3 | 400β800 ms | Edge AI deployment with optimization |
Performance depends on:
- YOLO model size
- Input resolution
- Camera FPS
- Optimization method
- Hardware acceleration
FALCON follows security practices to protect system data, credentials, and access.
- User registration system
- Password hashing
- Secure session management
- Protected dashboard access
- Environment variables used for sensitive credentials
- API keys excluded from GitHub
- Database access controlled through backend modules
- Secure configuration management
- Local inference support
- Reduced dependency on external cloud services
- Evidence stored locally
- Controlled access to detection records
Recommended production improvements:
- HTTPS implementation
- Firewall configuration
- Role-based access control
- Database encryption
- Secure API authentication
Although FALCON provides automated AI-based surveillance, some limitations exist:
- Accuracy depends on dataset quality
- False positives may occur
- Poor lighting can reduce detection performance
- Small or hidden objects may be difficult to detect
- Raspberry Pi has limited computational power
- High-resolution streams require optimization
- Multiple camera processing requires additional resources
- Camera positioning affects detection accuracy
- Network stability is required for RTSP cameras
- Extreme weather conditions may affect camera performance
- Twilio requires internet connectivity
- SMS delivery depends on network availability
FALCON is designed as an expandable AI surveillance platform.
Future development will focus on improving intelligence, scalability, and real-world deployment.
- Improve YOLOv8 model accuracy
- Increase detection speed
- Optimize database operations
- Improve dashboard analytics
- Add advanced reporting system
- Improve authentication security
- Deploy complete system on Raspberry Pi 5
- Optimize YOLO using ONNX
- TensorRT acceleration support
- Multi-camera monitoring
- Real-time WebSocket communication
- Offline edge inference
- Person detection and tracking
- Suspicious activity detection
- Behaviour analysis
- Threat scoring system
- Multiple object tracking
- Crime pattern analysis
- Cloud deployment
- Distributed surveillance network
- Mobile application
- GPS location tracking
- Google Maps integration
- Enterprise monitoring dashboard
- Smart city security integration
Contributions, issues, and feature requests are welcome.
Steps:
Fork the repository.
Create a feature branch.
Commit your changes.
Open a Pull Request.
git checkout -b feature/new-featureThis project is licensed under the MIT License.
You are free to:
- Use
- Modify
- Distribute
- Improve
provided that proper credit is given.
Backend Developer β’ AI Systems Developer β’ Computer Vision Enthusiast
π§ Email:
π LinkedIn
https://linkedin.com/in/astik-mohapatra
π GitHub
If you find this project useful:
β Star the repository
π΄ Fork the repository
π’ Share the project
Built with:
Python β’ YOLOv8 β’ OpenCV β’ Flask β’ SQLite β’ Twilio β’ Raspberry Pi
π¦ FALCON
Automatic Crime Alert and Reporting System





