An advanced AI-powered home surveillance system integrating computer vision, real-time processing, and intelligent notifications
HMS is a sophisticated home monitoring solution that leverages the power of artificial intelligence and edge computing to provide real-time surveillance capabilities. Built on the Raspberry Pi 5 platform, it combines state-of-the-art object detection with efficient video streaming and intelligent notification systems.
- Real-time human detection and tracking
- Low-latency video streaming
- Resource-efficient edge computing
- Intelligent alert system
- User-friendly web interface
-
YOLOv8 Neural Network
- Optimized NCNN model for edge deployment
- Real-time object detection at ~20-30 FPS
- Custom-trained on surveillance scenarios
- Efficient model quantization for Raspberry Pi
-
Image Processing
- OpenCV-based frame processing
- Real-time video stream optimization
- Adaptive frame rate control
- Memory-efficient buffer management
-
FastAPI Server
app = FastAPI() @app.get("/") def video_feed(): return StreamingResponse( generate_frames(), media_type="multipart/x-mixed-replace; boundary=frame" )
- Asynchronous request handling
- MJPEG streaming implementation
- RESTful API endpoints
- Websocket support for real-time updates
-
Camera Interface
picam2 = Picamera2() picam2.preview_configuration.main.size = (640, 480) picam2.preview_configuration.main.format = "RGB888" picam2.configure("preview")
- Direct hardware access
- Configurable resolution and format
- Optimized frame capture
- Hardware-accelerated processing
-
Next.js Application
- Server-side rendering for optimal performance
- Dynamic route handling
- Client-side state management
- Responsive design implementation
-
Real-time Updates
const streamUrl = process.env.NEXT_PUBLIC_CAMERA_URL; const videoRef = useRef<HTMLImageElement>(null); useEffect(() => { if (videoRef.current) { videoRef.current.src = streamUrl; } }, [streamUrl]);
- Live stream integration
- Dynamic content updates
- Efficient DOM manipulation
- Browser compatibility handling
def send_email():
global last_email_time
current_time = time.time()
if current_time - last_email_time < 120: # 2-minute cooldown
return
try:
yag = yagmail.SMTP(SENDER_EMAIL, APP_PASSWORD)
yag.send(
to=RECEIVER_EMAIL,
subject="Alert: Human Detected!",
contents="Human detected by surveillance system."
)
last_email_time = current_time
except Exception as e:
print(f"Failed to send email: {e}")- Rate-limited notifications
- SMTP email integration
- Error handling and retry logic
- Customizable alert templates
# YOLOv8 Configuration
model = YOLO("yolov8n_ncnn_model")
results = model.predict(
frame,
imgsz=320, # Reduced size for performance
conf=0.5, # Confidence threshold
iou=0.4, # NMS IoU threshold
max_det=10 # Max detections per frame
)- Inference Speed: 20-30 FPS on Raspberry Pi 5
- Detection Accuracy: >90% for human detection
- Latency: <100ms end-to-end
- Memory Usage: ~500MB RAM during operation
- Frame Capture
frame = picam2.capture_array()
- AI Processing
results = model.predict(frame)
- Frame Annotation
annotated_frame = results[0].plot()
- Stream Encoding
ret, buffer = cv2.imencode('.jpg', annotated_frame)
- Raspberry Pi 5 (4GB+ RAM)
- Raspberry Pi Camera Module v3
- Adequate cooling solution
- Stable power supply (3A recommended)
- Raspberry Pi OS (64-bit recommended)
- Python 3.9+
- Node.js 18+
- Git
- Stable network connection
- Port forwarding (if remote access needed)
- Sufficient bandwidth (>2Mbps upload)
# Update system packages
sudo apt update && sudo apt upgrade
# Install system dependencies
sudo apt install -y python3-pip python3-venv nodejs npm gitgit clone https://github.com/recursionReaper/HMS.git
cd HMS# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install Python dependencies
pip install -r requirements.txt
# Install NCNN dependencies
sudo apt install -y cmake build-essentialcd hms-next
npm install# Create .env file
cat > .env << EOL
NEXT_PUBLIC_CAMERA_URL=http://localhost:8000
NOTIFICATION_COOLDOWN=120
DETECTION_CONFIDENCE=0.5
EOL# Model configuration options
model_config = {
'imgsz': 320, # Input image size
'conf': 0.5, # Confidence threshold
'iou': 0.4, # NMS IoU threshold
'max_det': 10, # Maximum detections
'device': 'cpu', # Inference device
'classes': [0], # Filter for humans only
}# Camera configuration
picam2.preview_configuration.main.size = (640, 480)
picam2.preview_configuration.main.format = "RGB888"
picam2.preview_configuration.align()
# JPEG encoding parameters
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]# Email settings
EMAIL_CONFIG = {
'SENDER': 'your-email@gmail.com',
'PASSWORD': 'app-specific-password',
'RECEIVER': 'recipient@gmail.com',
'COOLDOWN': 120, # seconds
'RETRY_ATTEMPTS': 3
}- Frame buffer optimization
- Garbage collection tuning
- Resource monitoring
- Cache management
- Thread pool management
- Process priority setting
- Background task scheduling
- Load balancing
- Frame compression
- Bandwidth throttling
- Connection pooling
- Error recovery
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch
- Implement changes
- Write/update tests
- Submit pull request
This project is licensed under the MIT License - see the LICENSE file for details.
-
Aniket Desai - @recursionReaper
- System Architecture
- Hardware Integration
- Backend architecture
- Performance Optimization
-
Yash Ogale - @yashogale30
- AI Model Development
- Frontend Development
- Stream Processing
- System Integration
- Ultralytics for YOLOv8
- Raspberry Pi Foundation
- Next.js Team
- FastAPI
