An intelligent IoT-based surveillance system featuring real-time face recognition, automatic access control, MQTT messaging, and email alerting capabilities powered by Raspberry Pi.
This advanced surveillance system combines computer vision, IoT communication, and embedded systems to create a comprehensive security solution. The system automatically recognizes authorized personnel, controls access mechanisms (solenoid locks/relays), and provides real-time notifications through MQTT and email alerts for security monitoring.
- π Real-time Face Recognition: Advanced LBPH (Local Binary Pattern Histogram) algorithm for accurate face detection
- π Automated Access Control: Integration with solenoid locks and relay systems for physical access management
- π‘ IoT Communication: MQTT protocol for real-time system status and remote command execution
- π§ Email Alerts: Automated SMTP notifications with image attachments for unknown person detection
- ποΈ Database Integration: MongoDB for persistent storage of user data and system logs
- π₯ Live Video Processing: Real-time video feed analysis with confidence-based recognition
- π± Remote Monitoring: MQTT-based remote system status monitoring and control
- Raspberry Pi 4: Main processing unit
- Pi Camera Module: Video capture and live streaming
- Solenoid Lock/Relay: Physical access control mechanism
- GPIO Interface: Hardware control and sensor integration
- Computer Vision: OpenCV, Face Recognition algorithms
- IoT Communication: MQTT (Paho-MQTT), Message Queuing
- Database: MongoDB for user management and logging
- Email Service: SMTP with Gmail integration
- Image Processing: NumPy, Base64 encoding
Smart-Surveillance-System/
βββ π core/ # Core face recognition modules
β βββ π face_recognition.py # Real-time recognition engine
β βββ πΈ image_capture.py # Face enrollment system
β βββ π§ model_training.py # LBPH model training
βββ π mqtt_smtp/ # Communication modules
β βββ π‘ mqtt_email_integration.py # MQTT & Email alerting
βββ π data/ # Training datasets
β βββ π face_data/ # Enrolled face images
βββ π models/ # Trained ML models
β βββ π€ face_recognizer.xml # LBPH recognition model
βββ π― main.py # System entry point
βββ βοΈ requirements.txt # Python dependencies
βββ π¦ setup.py # Package configuration
- Detection: Haar Cascade classifiers for robust face detection
- Preprocessing: Histogram equalization and image normalization
- Training: LBPH (Local Binary Pattern Histogram) algorithm
- Recognition: Confidence-based matching with adjustable thresholds
- Optimization: Real-time performance with 100x100 image standardization
- MQTT Broker: Eclipse Mosquitto for message queuing
- Command Interface: Remote system control (status, hello, reset commands)
- Real-time Logging: Timestamped system events and recognition logs
- Quality of Service: QoS level 1 for reliable message delivery
- Email Notifications: Automated alerts with face image attachments
- Duplicate Prevention: Smart flagging to prevent spam emails
- SMTP Security: TLS encryption and app password authentication
- Image Processing: Base64 encoding for secure image transmission
- Raspberry Pi Configuration
sudo raspi-config
# Enable camera interface
# Configure GPIO pins for solenoid control
- Physical Connections
- Connect Pi Camera to camera port
- Wire solenoid lock to GPIO pins (configurable)
- Ensure proper power supply for peripherals
- Clone Repository
git clone https://github.com/het004/Smart-Surveillance-Face-Recognition-and-Activation-System-Powered-by-Raspberry-Pi-and-MQTT.git
cd Smart-Surveillance-Face-Recognition-and-Activation-System-Powered-by-Raspberry-Pi-and-MQTT
- Virtual Environment Setup
python3 -m venv surveillance_env
source surveillance_env/bin/activate
- Install Dependencies
pip install -r requirements.txt
- MongoDB Setup
sudo apt-get install mongodb
sudo systemctl start mongodb
sudo systemctl enable mongodb
Configure MQTT Settings (mqtt_smtp/mqtt_email_integration.py
):
MQTT_BROKER = "your-mqtt-broker.com"
MQTT_PORT = 1883
MQTT_TOPIC_STATUS = "surveillance/status"
MQTT_TOPIC_COMMANDS = "surveillance/commands"
Configure Email Alerts:
SMTP_SERVER = "smtp.gmail.com"
EMAIL_SENDER = "your-email@gmail.com"
EMAIL_PASSWORD = "your-app-password"
EMAIL_RECEIVER = "security-team@company.com"
python main.py
# Select option 1: Add new person
# Follow prompts to capture 200 face images
# Automatic image preprocessing and storage
python main.py
# Select option 2: Train model
# LBPH algorithm trains on enrolled faces
# Model saved as face_recognizer.xml
python main.py
# Select option 3: Start recognition
# Real-time video processing begins
# Automatic access control activation
python main.py
# Select option 4: Launch MQTT/SMTP system
# Full IoT integration with remote monitoring
# Email alerts for unknown persons
class FaceRecognitionSystem:
- LBPH recognizer with confidence thresholding
- Real-time video processing at 30 FPS
- Automatic face detection and tracking
- Multi-scale detection for varying distances
class MQTTHandler:
- Bidirectional MQTT communication
- JSON message formatting
- Connection resilience and auto-reconnect
- Command processing and response generation
class MongoDBManager:
- User profile storage with image data
- Recognition event logging
- System status tracking
- Base64 image encoding for storage
- True Positive Rate: >95% for enrolled users
- False Positive Rate: <5% with proper training
- Recognition Time: <200ms per frame
- Training Time: ~30 seconds for 50 images per person
- Video Resolution: 640x480 (configurable)
- Frame Rate: 30 FPS real-time processing
- Storage: ~50KB per enrolled face image
- Memory Usage: <512MB RAM during operation
- Confidence-based Authentication: Adjustable threshold (default: 80%)
- Unknown Person Detection: Automatic alerting and logging
- Physical Security: Solenoid lock integration for doors/gates
- Remote Monitoring: MQTT status updates for security teams
- Encrypted Communication: TLS encryption for email notifications
- Secure Storage: MongoDB with authentication support
- Image Processing: Local processing without cloud dependencies
- Privacy Compliance: On-device face recognition processing
surveillance/commands:
- "status" β Returns current system status
- "hello" β System connectivity test
- "reset" β System reset command
- Custom commands easily extensible
- Trigger: Unknown person detection
- Content: Timestamped alert with face image
- Frequency: Smart duplicate prevention
- Format: HTML with embedded images
{
"person_id": "USER001",
"status": "Opened/Locked",
"timestamp": "2024-01-15T10:30:00Z",
"confidence": 92.5
}
- User recognition frequency
- System access patterns
- Unknown detection events
- Performance metrics tracking
Author: Het Shah
Email: hetshah1718@gmail.com
GitHub: @het004
- Computer Vision Expertise: Advanced OpenCV implementations
- IoT Architecture: MQTT protocol integration and real-time communication
- Database Design: NoSQL data modeling with MongoDB
- Hardware Integration: Raspberry Pi GPIO programming
- Security Implementation: Multi-layered authentication and alerting
opencv-python>=4.5.0 # Computer vision processing
face_recognition>=1.3.0 # Face detection and recognition
paho-mqtt>=1.6.0 # MQTT communication protocol
pymongo>=4.0.0 # MongoDB database integration
numpy>=1.21.0 # Numerical computing
setuptools # Package management
- Raspberry Pi 4 (2GB RAM minimum, 4GB recommended)
- Pi Camera Module v2.1 or higher
- MicroSD Card 32GB Class 10
- Solenoid Lock 12V DC (or compatible relay module)
- Power Supply 5V 3A for Raspberry Pi
- Deep Learning Integration: CNN-based face recognition for improved accuracy
- Multi-Camera Support: Distributed surveillance with camera arrays
- Mobile Application: Flutter-based mobile monitoring app
- Facial Mask Detection: COVID-19 compliance monitoring
- Age & Gender Recognition: Advanced demographic analysis
- Docker Containerization: Easy deployment and scaling
- REST API Development: Web service integration
- Cloud Integration: AWS IoT and Azure IoT Hub support
- Edge Computing: Optimization for edge devices
- Office Buildings: Employee access control and attendance
- Residential Complexes: Visitor management and security
- Retail Stores: Customer recognition and loss prevention
- Educational Institutions: Student access and safety monitoring
- Manufacturing Plants: Authorized personnel access control
- Data Centers: High-security area monitoring
- Healthcare Facilities: Patient and staff identification
- Government Buildings: Multi-level security implementation
This project is open-source under the MIT License, encouraging collaboration and innovation in IoT security solutions.
- Fork the repository and create feature branches
- Follow PEP 8 coding standards
- Include comprehensive unit tests
- Document new features thoroughly
- Submit pull requests with detailed descriptions
π Star this repository if you find it valuable for your IoT security projects!
π€ Connect with me for collaboration on computer vision, IoT, and embedded systems projects.