Skip to main content

Real-time driver monitoring SDK — drowsiness, phone, seatbelt and smoking detection

Project description

SafeDrive AI

Real-time driver monitoring SDK — drowsiness, phone, seatbelt, and smoking detection via webcam. No special hardware required.

PyPI version HuggingFace GitHub


Install

pip install safedrive-ai           # MediaPipe pipeline
pip install safedrive-ai ultralytics  # + YOLO pipeline

Quick Start

from safedrive import DrowsinessDetector

# MediaPipe + MobileNet pipeline (CPU friendly)
detector = DrowsinessDetector(pipeline="mediapipe")

# YOLOv8 pipeline (all features: phone, seatbelt, cigarette)
detector = DrowsinessDetector(pipeline="yolo")

@detector.on_drowsy
def handle(event):
    print(f"Level {event.level}: {event.message}")

detector.run(camera=0)

Models auto-download from HuggingFace on first run.


Pipelines

pipeline="mediapipe" — MediaPipe + MobileNetV3

Two-stage pipeline. MediaPipe extracts 468 face landmarks → EAR geometry formula → eye crop → MobileNetV3 classifier (97.99% accuracy). Best for CPU-only.

pipeline="yolo" — YOLOv8-nano

Single forward pass detects all 9 classes simultaneously. Custom-trained on 28,593 images.

Metric Value
mAP50 0.940
mAP50-95 0.793
Inference 3.7ms/frame
Model size 6.3MB

Features

Feature mediapipe yolo
Eye state (3-class)
Yawn detection
Head pose
PERCLOS tracking
Phone detection
Seatbelt monitoring
Cigarette detection

Alert Levels

Level 1  WARNING   eyes half 3s / yawn / head tilt > 15°
Level 2  ALERT     eyes closed 2s / head nod > 25°
Level 3  CRITICAL  eyes closed 4s / face gone 2s

Phone / cigarette → instant DISTRACTION alert
Seatbelt removed  → continuous SAFETY alert

Usage Examples

All event types

detector = DrowsinessDetector(pipeline="yolo")

@detector.on_drowsy
def drowsy(event):
    print(f"Level {event.level}: {event.message}")

@detector.on_distraction
def distraction(event):
    print(f"{event.type} detected")   # "phone" or "smoking"

@detector.on_safety
def safety(event):
    print(event.message)              # seatbelt events

detector.run(camera=0)

Disable features

# Testing without seatbelt or cigarette
detector = DrowsinessDetector(
    pipeline        = "yolo",
    detect_seatbelt = False,
    detect_smoking  = False,
)

Custom thresholds

detector = DrowsinessDetector(
    pipeline           = "yolo",
    eye_close_seconds  = 1.5,    # alert faster (default 2.0)
    head_tilt_degrees  = 20.0,   # more lenient (default 15.0)
)

Headless

detector = DrowsinessDetector(pipeline="yolo", show_window=False)

@detector.on_frame
def process(frame, stats):
    # stats.eye_state, stats.fps, stats.alert_level, stats.perclos
    pass

detector.run()

Changelog

v0.2.1

  • Feature disable flags (detect_phone, detect_seatbelt, detect_smoking, detect_yawn)

v0.2.0

  • YOLOv8-nano pipeline — phone, seatbelt, cigarette detection
  • mAP50 = 0.940 on 9-class custom dataset

v0.1.1

  • HuggingFace auto-download, local model cache

v0.1.0

  • Initial release — MediaPipe + MobileNetV3 pipeline

Links: GitHub · HuggingFace · PyPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safedrive_ai-0.2.2.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safedrive_ai-0.2.2-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file safedrive_ai-0.2.2.tar.gz.

File metadata

  • Download URL: safedrive_ai-0.2.2.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for safedrive_ai-0.2.2.tar.gz
Algorithm Hash digest
SHA256 9deb1511d7daab09ea77244b6d43c8bd23ea582abe9c17cd1be48f5f26a0f4fc
MD5 91c150e52acbf8762e50c032c9ae7067
BLAKE2b-256 3e3fb130bf3a0a97484c56aaf6240701bd39c59dfdb63572e7041bc204099f94

See more details on using hashes here.

File details

Details for the file safedrive_ai-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: safedrive_ai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for safedrive_ai-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7d36d80ae6548a6b3f06cf45be594e77ed23fbdb641f6c970f0c49062e5c9578
MD5 9b059f627ebbfdef32d7f54d0ad87967
BLAKE2b-256 e7d6b1676f704ebe62ed7531bdc8a235a98f20605f19b4bc4577b112d9047b84

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page