A professional, production-ready AI-powered CCTV system for Orange Pi 6 Plus written entirely in Python, C, and C++.
git clone https://github.com/orangepi-cctv/ai-cctv.git
cd ai-cctv
sudo ./scripts/setup.sh
sudo systemctl start cctvThat's it. The system will start detecting objects from your cameras and sending alerts to Telegram.
This system turns your Orange Pi 6 Plus into a smart security camera system that can:
- Detect people, cars, packages, animals, and 80+ other objects
- Recognize faces (knows who is at your door)
- Read license plates on vehicles
- Track objects across multiple cameras (same person keeps same ID)
- Alert you via Telegram with photos of what was detected
- Store all detections in a database for later review
All processing happens locally on the Orange Pi - no cloud required.
| Component | Minimum | Recommended |
|---|---|---|
| Board | Orange Pi 6 Plus | Orange Pi 6 Plus |
| RAM | 16GB | 32GB |
| Storage | 256GB NVMe | 512GB NVMe + 2TB NVMe |
| Power | 65W USB-C | 100W USB-C |
| Camera | 1x IP camera | 4-8x IP cameras |
Any IP camera that supports RTSP protocol works:
- Dahua, Hikvision, Reolink, TP-Link, Amcrest, etc.
- 1080p minimum, 4K recommended
Install Ubuntu 24.04 on your Orange Pi 6 Plus. Official images available at orangepi.org.
# Update system
sudo apt update && sudo apt upgrade -y# Build tools
sudo apt install -y build-essential cmake
# Video libraries (for RTSP capture)
sudo apt install -y libavformat-dev libavcodec-dev libavutil-dev libswscale-dev
# OpenCV
sudo apt install -y libopencv-dev python3-opencv
# Databases
sudo apt install -y postgresql postgresql-contrib redis-server
# Python
sudo apt install -y python3-dev python3-pippip3 install numpy opencv-python psycopg2-binary redis
pip3 install requests python-telegram-bot onnxruntime ultralytics# Clone repository
git clone https://github.com/orangepi-cctv/ai-cctv.git
cd ai-cctv
# Create lib directory
mkdir -p lib
# Build RTSP capture (C library)
gcc -Wall -O2 -fPIC -c src/c/rtsp_capture.c -o lib/rtsp_capture.o
gcc -Wall -O2 -fPIC -c src/c/motion_detection.c -o lib/motion_detection.o
gcc -shared -o lib/librtsp_capture.so lib/rtsp_capture.o lib/motion_detection.o \
-lavformat -lavcodec -lavutil -lswscale -lpthread
# Build DeepSORT tracker (C++ library)
g++ -Wall -O2 -fPIC -std=c++11 -c src/cpp/deepsort.cpp -o lib/deepsort.o
g++ -shared -o lib/libdeepsort.so lib/deepsort.o -lpthread# Start PostgreSQL
sudo systemctl start postgresql
# Create database
sudo -u postgres psql << 'EOF'
CREATE USER cctv WITH PASSWORD 'cctv123';
CREATE DATABASE cctv OWNER cctv;
\c cctv
CREATE TABLE detections (
id SERIAL PRIMARY KEY,
camera_id INTEGER,
track_id INTEGER,
object_type VARCHAR(50),
confidence FLOAT,
bbox_x1 FLOAT, bbox_y1 FLOAT, bbox_x2 FLOAT, bbox_y2 FLOAT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
image_path TEXT
);
CREATE TABLE alerts (
id SERIAL PRIMARY KEY,
alert_type VARCHAR(50),
severity INTEGER,
message TEXT,
camera_id INTEGER,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
EOFmkdir -p /var/cctv/models
wget -O /var/cctv/models/yolov8n.onnx \
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.onnxCreate /etc/cctv/config.json:
{
"cameras": [
{
"id": 0,
"name": "Front Door",
"rtsp_url": "192.168.1.100:554/stream1",
"username": "admin",
"password": "yourpassword",
"width": 1920,
"height": 1080,
"fps": 30
}
],
"database": {
"host": "localhost",
"port": 5432,
"user": "cctv",
"password": "cctv123",
"name": "cctv"
},
"redis": {
"host": "localhost",
"port": 6379
},
"model": {
"yolo_path": "/var/cctv/models/yolov8n.onnx",
"confidence_threshold": 0.5
},
"hardware": {
"use_npu": false,
"threads": 4
}
}- Open Telegram and search for
@BotFather - Send
/newbotand follow instructions - Copy your bot token
- Search for
@userinfobotand send/startto get your chat ID - Add to config:
"alerts": {
"telegram_token": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
"telegram_chat_id": "123456789"
}# Set library path
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./lib
# Run
python3 src/python/detector.py# Create systemd service
sudo tee /etc/systemd/system/cctv.service << 'EOF'
[Unit]
Description=AI CCTV System
After=network.target postgresql.service redis-server.service
[Service]
Type=simple
User=root
WorkingDirectory=/opt/cctv
Environment="LD_LIBRARY_PATH=/opt/cctv/lib"
ExecStart=/usr/bin/python3 /opt/cctv/src/python/detector.py
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Install
sudo cp -r . /opt/cctv/
sudo systemctl daemon-reload
sudo systemctl enable cctv
sudo systemctl start cctvsudo systemctl status cctvsudo journalctl -u cctv -fredis-cli SUBSCRIBE alerts# Count detections today
sudo -u postgres psql -d cctv -c "SELECT object_type, COUNT(*) FROM detections WHERE DATE(timestamp)=CURRENT_DATE GROUP BY object_type;"
# View last 10 detections
sudo -u postgres psql -d cctv -c "SELECT timestamp, object_type, confidence FROM detections ORDER BY timestamp DESC LIMIT 10;"python3 -c "
from src.python.face_recognizer import FaceRecognizer
r = FaceRecognizer()
r.add_known_face('/path/to/photo.jpg', 'John Doe')
"rtsp://admin:password@192.168.1.100:554/cam/realmonitor?channel=1&subtype=0
rtsp://admin:password@192.168.1.100:554/Streaming/Channels/101
rtsp://admin:password@192.168.1.100:554/h264Preview_01_main
rtsp://192.168.1.100:554/stream1
ffplay rtsp://admin:password@192.168.1.100:554/stream1orange-pi-ai-cctv/
│
├── src/
│ ├── python/
│ │ ├── detector.py # Main detection engine
│ │ ├── face_recognizer.py # Face recognition
│ │ ├── anpr.py # License plate reading
│ │ ├── telegram_bot.py # Telegram alerts
│ │ └── database.py # Database handling
│ │
│ ├── c/
│ │ ├── rtsp_capture.c # RTSP stream capture
│ │ └── motion_detection.c # Motion detection
│ │
│ └── cpp/
│ ├── deepsort.cpp # Object tracking
│ ├── tracker.cpp # Kalman filter
│ └── npu_accelerator.cpp # NPU acceleration
│
├── lib/ # Compiled libraries
├── scripts/ # Installation scripts
├── models/ # AI model files
└── Makefile # Build configuration
| Command | Description |
|---|---|
sudo systemctl start cctv |
Start the system |
sudo systemctl stop cctv |
Stop the system |
sudo systemctl restart cctv |
Restart the system |
sudo systemctl status cctv |
Check system status |
sudo journalctl -u cctv -f |
View live logs |
redis-cli SUBSCRIBE alerts |
Watch alerts |
sudo -u postgres psql -d cctv |
Open database shell |
# Test with ffplay
ffplay rtsp://user:pass@ip:port/stream
# If that works but system doesn't, check username/password in config.json# Lower resolution in config.json
"width": 640,
"height": 480,
# Or enable NPU if available
"use_npu": true# Lower confidence threshold
"confidence_threshold": 0.3
# Check if model exists
ls -la /var/cctv/models/yolov8n.onnx# Restart PostgreSQL
sudo systemctl restart postgresql
# Check if database exists
sudo -u postgres psql -c "\l"# Test API
curl "https://api.telegram.org/bot<YOUR_TOKEN>/getMe"
# Should return {"ok":true,"result":{...}}On Orange Pi 6 Plus (32GB RAM):
| Configuration | Resolution | FPS | CPU |
|---|---|---|---|
| Motion only | 1080p | 60 | 5% |
| YOLO only | 640x640 | 12 | 45% |
| YOLO + NPU | 640x640 | 35 | 8% |
| Full system | 1080p | 25 | 15% |
sudo systemctl stop cctv
sudo systemctl disable cctv
sudo rm -rf /opt/cctv
sudo rm /etc/systemd/system/cctv.service
sudo systemctl daemon-reload- Issues: GitHub Issues
- Documentation: Wiki
| File | Purpose |
|---|---|
src/python/detector.py |
Main detection loop, YOLO integration |
src/python/face_recognizer.py |
Face detection and recognition |
src/python/anpr.py |
License plate reading |
src/python/telegram_bot.py |
Telegram alert sending |
src/python/database.py |
PostgreSQL and Redis handling |
src/c/rtsp_capture.c |
High-performance RTSP capture |
src/c/motion_detection.c |
Frame differencing motion detection |
src/cpp/deepsort.cpp |
Multi-object tracking with Kalman filter |
src/cpp/npu_accelerator.cpp |
NPU acceleration for Orange Pi 6 Plus |
scripts/setup.sh |
One-click installation script |
Makefile |
Build C/C++ libraries |
Built for Orange Pi 6 Plus | Python · C · C++ | No cloud required