# How We Built a Real-Time Edge-AI Theft Detection System on a Raspberry Pi 4 + Telegram Alerts

> Source: <https://dev.to/devdestiny/how-we-built-a-real-time-edge-ai-theft-detection-system-on-a-raspberry-pi-4-telegram-alerts-20p1>
> Published: 2026-11-04 07:51:36+00:00

Traditional surveillance systems often rely on heavy cloud infrastructure or manual monitoring, which introduces latency and high bandwidth costs. 

For retail environments, security needs to be instantaneous, local, and cost-effective. To solve this, we developed an Intelligent Video-Based Theft Detection and Alert System as part of our Computer Engineering final year project at FUTMinna. 

We built an edge-computing solution running entirely on a Raspberry Pi 4 Model B (4GB) that detects retail threats and pushes instant alerts to Telegram in an average of 2.1 seconds.

Here is a breakdown of how the system architecture, hybrid AI pipeline, and alert mechanisms were engineered.

Running heavy neural networks on resource-constrained hardware is challenging. We chose the Raspberry Pi 4 Model B (4GB RAM) paired with the Raspberry Pi Camera Module v2 (connected natively via the CSI port for low CPU overhead). By processing video locally at 640x480 resolution, the system achieved a steady 25–31 FPS without requiring external cooling or cloud dependencies.

Instead of relying on a single heavy model that would choke a Raspberry Pi, we engineered a three-detection pipeline that runs concurrently:

**Pipeline 1 - Masked-Face Detection (Haar Cascades)**:

It Rapidly localizes frontal faces using lightweight Haar cascades adn then extracts the lower 40% of the bounding box (mouth/chin area) and calculates mean pixel intensity to flag hidden identities.   

**Pipeline 2 - Weapon & Sharp Object Detection (MobileNetV2)**:

Uses a custom Haar cascade to isolate hand regions, resizing ROIs to 224 X 224 pixels which passes the region through a MobileNetV2 model trained via transfer learning on a balanced dataset of weapon and non-weapon hand images.   

**Pipeline 3 - Pocketing & Concealment Detection (MOG2 Background Subtraction)**:

When any of these three modules trigger a positive detection, the system elevates into a global "THEFT ALERT" state.

Instead of relying on clunky email protocols or expensive SMS gateways, we integrated the Telegram Bot API.

To allow remote monitoring without an attached HDMI monitor, we built a lightweight web server using the Flask micro-framework. Using classic MJPEG streaming (multipart/x-mixed-replace), store owners can view the live camera feed, bounding boxes, and alert statuses straight from any smartphone or laptop browser connected to the local network.

This project proved that high-accuracy, real-time edge AI is entirely feasible on budget-friendly hardware like the Raspberry Pi without sacrificing performance or relying on expensive cloud subscriptions.
