April 5, 2025

Mask detection and alert system

Project thumbnail

This was a fun and timely project born during the pandemic. One day I saw a sign in my apartment building that read: β€œMandatory use of masks in all areas”, and I found myself wondering: β€œBut how would anyone actually check?”

With a Raspberry Pi equipped with a camera sitting idle, I built an end-to-end system to monitor mask usage in real time. If someone was detected without a mask, the system would automatically send a WhatsApp alert.

The pipeline included:

  • πŸ–ΌοΈ Building a small custom dataset of masked and unmasked faces
  • πŸŽ₯ Using a Raspberry Pi camera as a real-time video stream source
  • πŸ§‘β€πŸ”¬ Running face detection to crop and extract face regions from each frame
  • 🧠 Training a CNN to classify mask usage
  • ☁️ Deploying the model to a cloud server with FastAPI for inference
  • πŸ“² Integrating WhatsApp notifications via Twilio

It was a lighthearted side project during uncertain times, and a great opportunity to work with hardware, computer vision, and real-time systems.

🧩 Features

  • 🧠 Real-time face detection and mask classification
  • πŸ“· Raspberry Pi as a low-cost edge device
  • ☁️ Cloud-hosted inference API for efficient processing
  • πŸ”” WhatsApp notifications for non-compliance alerts
  • πŸ§ͺ Custom training pipeline with CNN model

πŸ’‘ Technologies used

  • OpenCV – Face detection and image processing
  • TensorFlow / Keras – CNN training for mask detection
  • FastAPI – Lightweight inference API
  • Raspberry Pi – Real-time video streaming hardware
  • Twilio API – WhatsApp messaging integration
  • Docker – Reproducible environment for running the server
  • Python – Core backend and data flow orchestration

🌐 Resources

πŸ‘‰ Github repo

πŸ‘‰ Blog post (in portuguese)