Table of Contents
- System Overview
- Hardware Options
- OpenCV Installation on Pi
- Person Detection with MobileNet-SSD
- Telegram Alert on Detection
- Performance Optimisation
- FAQ
System Overview
A smart surveillance camera with OpenCV object detection uses AI-based computer vision to distinguish people from animals, vehicles, and other moving objects – eliminating the false alarms that plague PIR-based systems. Running on Raspberry Pi 5, it processes live camera feed, detects persons with 80-90% accuracy, and sends Telegram alerts with a snapshot photograph. Build cost: Rs 5,000-8,000 versus commercial AI cameras at Rs 8,000-25,000 (Hikvision DeepinView, Dahua WizSense).
Hardware Options
| Platform | FPS (MobileNet-SSD) | Cost India | Notes |
|---|---|---|---|
| Raspberry Pi 5 (8GB) | 8-12 FPS | Rs 8,000-10,000 | Best for Indian DIY, good community support |
| Raspberry Pi 5 (4GB) | 6-10 FPS | Rs 6,500-8,000 | Adequate for single camera |
| Jetson Nano (GPU) | 20-30 FPS | Rs 12,000-18,000 | Better for multi-camera systems |
| Orange Pi 5 | 15-20 FPS (NPU) | Rs 5,000-7,000 | NPU acceleration for AI workloads |
OpenCV Installation on Pi
# Install on Raspberry Pi OS (Bookworm)
sudo apt update
sudo apt install -y python3-opencv python3-pip
pip3 install opencv-contrib-python imutils
# Test camera
python3 -c "import cv2; cap=cv2.VideoCapture(0); print(cap.isOpened())"
Person Detection with MobileNet-SSD
import cv2
import numpy as np
# Load pre-trained person detector (MobileNet-SSD)
net = cv2.dnn.readNetFromCaffe('deploy.prototxt', 'mobilenet.caffemodel')
cap = cv2.VideoCapture(0) # Arducam or USB camera
while True:
ret, frame = cap.read()
if not ret: break
h, w = frame.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(frame,(300,300)),
0.007843,(300,300),127.5)
net.setInput(blob)
detections = net.forward()
for i in range(detections.shape[2]):
confidence = detections[0,0,i,2]
classID = int(detections[0,0,i,1])
if confidence > 0.5 and classID == 15: # person class
box = detections[0,0,i,3:7] * np.array([w,h,w,h])
x1,y1,x2,y2 = box.astype(int)
cv2.rectangle(frame,(x1,y1),(x2,y2),(0,255,0),2)
print(f"Person detected! Confidence: {confidence:.2f}")
# Trigger Telegram notification with snapshot
cv2.imshow('Surveillance', frame)
if cv2.waitKey(1) & 0xFF == ord('q'): break
cap.release()
Telegram Alert on Detection
import requests, cv2
def send_telegram_photo(bot_token, chat_id, frame):
_, buf=cv2.imencode('.jpg', frame)
url=f"https://api.telegram.org/bot{bot_token}/sendPhoto"
requests.post(url,
data={'chat_id':chat_id,'caption':'Person detected!'},
files={'photo':('alert.jpg',buf.tobytes(),'image/jpeg')},
timeout=10)
Performance Optimisation
- Region of interest masking: Only process detection in relevant zones (doorway, gate area) and ignore sky, ground. Reduces compute by 40-60%.
- Frame skipping: Process every 3rd frame for detection while displaying all frames. 3x faster detection loop.
- Resolution reduction: Run detection at 320×320 while recording at full 1920×1080. Scales linearly with resolution.
- Hardware acceleration: On Pi 5, use OpenCV with NEON SIMD optimisation (enabled by default in Pi OS build). Enable Video4Linux2 (V4L2) camera interface for lower latency CSI capture.
Frequently Asked Questions
What is the accuracy of person detection vs motion detection?
MobileNet-SSD person detection achieves 80-90% detection rate with 5-10% false positive rate in typical Indian outdoor conditions. Standard PIR motion detectors have near-zero false negatives but 30-60% false positive rate (dogs, cats, wind-blown leaves, air conditioners). For Indian residential use, AI detection significantly reduces false alarm notifications while maintaining reliable intruder detection.
Can this system run 24/7 on Raspberry Pi without overheating?
Raspberry Pi 5 running continuous OpenCV object detection reaches 60-70 degrees CPU temperature at 8-12 FPS. At this temperature (within spec, max 85C), the Pi throttles slightly but remains stable. Use a proper heatsink and active cooling fan case. In Indian summer with ambient 35-40C ambient, a case with active fan is essential for 24/7 operation. Monitor temperature with vcgencmd measure_temp command.
Does this work with the Arducam PTZ camera for auto-tracking?
Yes – combine MobileNet-SSD detection with Arducam PTZ controller (available via Python libcamera or ArduCam PTZ library). When a person is detected, calculate the centroid of their bounding box, compare to frame centre, and send pan/tilt commands to centre the camera on the detected person. This creates an active tracking surveillance camera similar to commercial auto-tracking cameras at 10x lower cost.
What happens to stored footage in Indian power cuts?
Implement graceful shutdown: detect power cut via UPS APC relay contact or voltage sensor, save current recording file properly before system shutdown, record power cut timestamp. At restart, begin new recording file. Use a 600VA UPS to give the Pi 1-2 hours of operation during cuts. Store recordings on USB SSD rather than SD card – SD cards are prone to corruption if power is cut during a write operation.
Add comment