CheapSecurity: Lightweight Self-Hosted CCTV for Linux SBCs

CheapSecurity: Lightweight Self-Hosted CCTV for Linux SBCs

CheapSecurity is a lightweight, self-hosted surveillance system designed to run on Linux-based single-board computers (SBCs) like Raspberry Pi or Orange Pi. It provides a privacy-first alternative to cloud-based cameras by keeping all video data local and utilizing standard USB webcams to eliminate recurring subscription fees.

Core Features and Capabilities

CheapSecurity transforms a low-power Linux device into a functional CCTV hub with integrated motion detection and remote alerting.

Monitoring and Recording

  • Live Streaming: Provides a live MJPEG stream accessible via a web dashboard.
  • Motion Detection: Uses frame differencing to identify movement, triggering automatic recordings.
  • Pre-motion Buffering: Includes a set amount of time before the motion trigger in the saved clip to provide full context.
  • Storage Management: Implements automatic cleanup based on file age, total storage size, and emergency low-disk space thresholds to prevent system crashes.

Notifications and Remote Access

  • Telegram Integration: Supports automatic video uploads upon motion detection and a bot interface for remote commands, including /snapshot for a current image and /video <seconds> for on-demand recording.
  • Email Alerts: Sends snapshots via SMTP when motion is detected, with configurable rate-limiting to avoid spam.
  • Web Dashboard: A centralized interface for viewing the live stream, monitoring system status (FPS, resolution), and managing recordings through bulk actions like ZIP downloads or deletions.

Low-Light Enhancement

CheapSecurity includes a "Night Mode" that applies software-based Contrast Limited Adaptive Histogram Equalization (CLAHE) and brightness/contrast boosts to the video feed. While it improves visibility in low light, the project documentation notes that true night vision requires IR-sensitive hardware and an IR illuminator.

Technical Architecture and Requirements

The system is built with Python and OpenCV, optimized for resource-constrained hardware.

System Requirements

  • Software: Python 3.10 or newer and OpenCV with V4L2 support.
  • Hardware: A Linux SBC and a USB webcam (defaulting to /dev/video0).
  • Deployment: Designed for production use with Gunicorn as the WSGI server and systemd for autostart capabilities.

Processing Pipeline

As analyzed by the community, the system follows a streamlined processing flow:

  1. Capture: V4L2 (MJPG) $\rightarrow$ cap.read().
  2. Enhancement: CLAHE is applied if Night Mode is active.
  3. Streaming: Frames are encoded to MJPEG for the web dashboard.
  4. Analysis: Frames are downscaled, converted to grayscale, blurred, and processed via absdiff and contours to detect motion.
  5. Output: If motion is detected, frames are written to disk; otherwise, they are stored in a pre-buffer. Completed clips are remuxed via ffmpeg for FPS correction before being sent to Telegram or email.

Installation and Setup

Deployment is split between development and production environments to ensure stability and security.

Installation Paths

  • ARM Boards (Recommended): Use the system OpenCV package via a virtual environment created with --system-site-packages to leverage board-specific optimizations.
  • x86/amd64 Machines: Install opencv-python-headless via pip for a self-contained environment.

Production Deployment

To avoid the security risks of the Flask development server, the project recommends using Gunicorn. The provided systemd template allows the application to run as a background service, binding to 0.0.0.0:5000 with one worker and four threads. Users are advised to place a reverse proxy with HTTPS and authentication in front of the service if exposing it to the internet.

Community Insights and Considerations

Discussion around the project highlights several trade-offs inherent in lightweight, open-source surveillance software.

Motion Detection Accuracy

Users have noted that naive frame-differencing—the method used by CheapSecurity—can be prone to false positives caused by shadows, wind-blown foliage, or insects. One community member contrasted this with high-end systems like Nest, which use more computationally expensive human-detection algorithms to reduce noise.

Hardware Limitations

There is a recurring concern regarding the availability of suitable USB cameras. Standard webcams often lack the rugged enclosures, precise focus, and low-light performance required for professional-grade security, emphasizing that the software's effectiveness is heavily dependent on the quality of the connected hardware.

Sources