Skip to content

Repository files navigation

Blink Counter – Raspberry Pi Zero 2W

Real-time blink detection system using a Raspberry Pi Zero 2W, Camera v3 (IMX708), TFLite, and MQTT.

Features

  • Real-time eye blink detection using a TFLite model with Haar Cascade face/eye detection
  • MQTT publishing of blink counts at configurable intervals with auto-reconnect
  • Web-based configuration portal (Flask) for Wi-Fi, MQTT, camera, and model settings
  • Automatic AP hotspot mode when Wi-Fi is unavailable (accessible at 192.168.4.1:5000)
  • Dual-stream Picamera2 pipeline: low-res YUV for fast inference, optional high-res for preview
  • Optimized for Pi Zero 2W: minimal CPU/RAM usage in headless mode

Quick Start

  1. Copy this folder to your Raspberry Pi Zero 2W
  2. Run the setup script:
    cd /path/to/blink-counter
    sudo bash setup.sh
  3. Reboot:
    sudo reboot
  4. The app starts automatically. Configure via the web portal at http://<pi-ip>:5000

Project Structure

File Description
TFlite_tester_Copy.py Main application script
eye_state_model2.tflite TFLite eye-state classification model
rpi_config.json Runtime configuration (Wi-Fi, MQTT, camera, thresholds)
setup.sh One-command installer for all dependencies
blink_app Bash launcher script (handles venv + root)
check_flask_ap.sh Diagnostic script for Flask/AP networking
autostart/ Desktop autostart entries

Configuration

Access the web portal at http://<pi-ip>:5000 to configure:

  • Wi-Fi: SSID and password
  • MQTT: Server, port, credentials, publish interval
  • Camera: Resolution, FPS, preview toggle
  • Model: Blink thresholds, detection stride, TFLite threads

Dependencies

All installed automatically by setup.sh:

  • python3-picamera2, libcamera-apps
  • python3-opencv
  • python3-flask
  • paho-mqtt
  • tflite-runtime (from piwheels)

Hardware

  • Raspberry Pi Zero 2W
  • Raspberry Pi Camera Module v3 (IMX708)

License

MIT

About

Real-time eye blink detection and counter for Raspberry Pi Zero 2W using TFLite, OpenCV Haar Cascades, Picamera2, MQTT, and Flask config portal

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages