This project demonstrates a real-time face detection system using:
- ESP32-CAM (without PSRAM) for capturing images
- TinyML model (.tflite) running on a Python Flask backend
- A web dashboard for displaying real-time detection and history
- Telegram bot integration for sending face detection alerts with image, timestamp, and location
Designed for low-resource hardware, this solution is lightweight and ideal for entry-level IoT AI applications.
- ESP32-CAM (AI Thinker)
- TensorFlow Lite (TFLite) for model inference
- Flask Web Framework (Python)
- OpenCV for image handling
- Telegram Bot API for notifications
- Real-time image capture from ESP32-CAM
- Face detection using quantized TFLite model
- Web dashboard to view latest image + status
- Instant Telegram alerts with location + timestamp
- Training notebook for building your own model
- Fast, works with low-resolution images (160x120)
- Open
esp32/esp32_cam_sender.inoin Arduino IDE - Update WiFi credentials and Flask server IP:
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_PASSWORD";
const char* serverUrl = "http://<your-pc-ip>:8000/upload";
- Set board to AI Thinker ESP32-CAM and flash the code
cd flask_app pip install -r requirements.txt python app.py
Make sure
face_detection.tfliteis inflask_app/model/
Visit http://localhost:8000 to open the dashboard.
- Create a bot via @BotFather
- Get your bot token and your own chat ID
- Replace in
app.py:
TELEGRAM_BOT_TOKEN = 'your_bot_token' TELEGRAM_CHAT_ID = 'your_chat_id' LOCATION = "Lab Entrance" # Customizable tag
- Open
notebook/train_and_convert.ipynb - Use a dataset like WIDER FACE or your custom face images
- Build a lightweight CNN model
- Export and quantize to TensorFlow Lite:
converter = tf.lite.TFLiteConverter.from_keras_model(model) converter.optimizations = [tf.lite.Optimize.DEFAULT] tflite_model = converter.convert()
- Save as
face_detection.tfliteand move it toflask_app/model/
Dashboard (/) shows:
- Latest image with face bounding boxes
- Detection status (face/no-face)
- Last detected time
- Auto-refreshing UI
- Power up ESP32-CAM
- Server receives
POSTimage every ~100ms - Flask runs inference on image using TFLite
- If face is found:
- Detection shown on dashboard
- Telegram alert sent with image
Flask==2.3.2
opencv-python==4.8.0.74
numpy==1.24.3
requests==2.31.0
tensorflow==2.12.0