Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raspberry Pi Driver Monitoring System

This project provides a Raspberry Pi oriented driver monitoring server built with Flask, OpenCV, MediaPipe model assets, and GPIO-based alerts.

It accepts uploaded JPEG frames, detects face and attention state, and exposes both a live MJPEG stream and JSON status output. The current runtime classifies:

  • NO_FACE
  • NORMAL
  • DISTRACTED
  • DROWSY

It also supports:

  • LED and buzzer alerts through Raspberry Pi GPIO
  • looped melodies for sustained DISTRACTED and DROWSY states
  • auto-download of required OpenCV cascade XML files if missing
  • systemd deployment for headless startup on boot

Repository Structure

  • pi_server.py: main Flask server and processing loop
  • models/face_landmarker.task: local face landmark model asset
  • cascades/: OpenCV cascade storage/download directory
  • driver_monitor.service: example systemd unit

Requirements

  • Python 3.10+
  • Raspberry Pi OS or another Linux environment
  • Camera client that posts JPEG frames to the server
  • Optional Raspberry Pi GPIO hardware for LED/buzzer output

Install Python dependencies:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Running Locally

Start the server:

python3 pi_server.py

Default server address:

  • http://0.0.0.0:5000/

Useful endpoints:

  • GET / : simple monitoring page
  • GET /status : JSON status and last frame age
  • GET /stream : MJPEG video stream
  • POST /frame : upload a frame under multipart field frame

Example frame upload:

curl -X POST http://127.0.0.1:5000/frame \
  -F "frame=@sample.jpg"

Example status check:

curl http://127.0.0.1:5000/status

GPIO Behavior

Current output logic:

  • NO_FACE: LED on, buzzer off
  • NORMAL: LED off, buzzer off
  • DISTRACTED: after 3 seconds, starts looping Fur Elise
  • DROWSY: after 3 seconds, starts looping Super Mario; after 6 seconds total, LED also turns on

If GPIO initialization fails, the app falls back to a mock backend and continues running without hardware control.

Deployment With systemd

An example service file is included as driver_monitor.service.

Before enabling it, update paths if your installation directory differs from /home/pi/driver-monitor.

Typical setup:

sudo cp driver_monitor.service /etc/systemd/system/driver_monitor.service
sudo systemctl daemon-reload
sudo systemctl enable driver_monitor.service
sudo systemctl start driver_monitor.service
sudo systemctl status driver_monitor.service

Notes

  • pi_server copy.py is a local backup copy and is intentionally excluded from version control.
  • The project expects models/face_landmarker.task to be present locally.
  • Haar cascade files are downloaded automatically if OpenCV cannot find them on the system.

About

Detecting the drivers face status and find out wheter it is drowsy, distracted and so on by using rasbery-py 3 micro controller

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages