跳到正文
DEV Community· Destiny Onoja·· 3 小時前AI 評分38

我們如何在 Raspberry Pi 4 上構建即時邊緣 AI 盜竊偵測系統並透過 Telegram 發送警報

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

AI 導讀

FUTMinna 電腦工程畢業專題團隊在 Raspberry Pi 4 Model B(4GB)上構建即時邊緣 AI 盜竊偵測系統,透過三條電腦視覺流程偵測遮臉、武器及藏匿物品行為。系統整體 F1 分數為 94.7%,以 25–31 FPS 處理影片,Telegram 警報平均在 2.1 秒內送達。

正文

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.

1. The Hardware Core: Why Edge Computing?

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.

2. The Hybrid Computer Vision Pipeline

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):

  • Utilizes OpenCV's MOG2 background subtraction algorithm restricted to the lower 40% of the frame.
  • Implements an 8-frame hysteresis counter to track foreground pixel changes (Pcount > 1500), successfully filtering out routine customer movements like browsing shelves or adjusting clothes.

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

3. Instant Alert Mechanism via Telegram Bot API

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

  • The Flow: When an anomaly is confirmed, the system saves an annotated JPEG of the frame locally and sends it to the user's Telegram chat with a timestamped caption ("BEWARE, POSSIBLE THEFT!").
  • Performance: Average delivery time was benchmarked at 2.1 seconds.
  • Cooldown Policy: An 8-second cooldown timer prevents message flooding during extended incidents while ensuring the very first alert arrives instantly.

4. Headless Monitoring via Flask Web UI

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.

Key Metrics & Results

  • Overall System F1-Score: 94.7% Masked Face
  • Precision/Recall: 96.4% / 93.8% Weapon Detection
  • Precision/Recall: 91.2% / 88.7% Pocketing
  • Detection Precision/Recall: 94.1% / 92.6%
  • Processing Speed: 25–31 FPS
  • Telegram Alerts: 2.1seconds

Conclusion

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.

來源:DEV Community · dev.to