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.1.tar.gz (19.2 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.1-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: safedrive_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 19.2 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.1.tar.gz
Algorithm Hash digest
SHA256 c257c4451831ec1a4115859fcea7309a834534809c2c53993341f369dd72ab57
MD5 71bff6bb4fc517f33551b6c51ac3f1e1
BLAKE2b-256 33d4d1b9c07d2e818adc7e607dc139a1fb72b6cae4ab8bddeb311b65b33c329b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: safedrive_ai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 09c2d0c487050d2f8f4370a724c8ba8cad9d13a20eb6f9bb6eedbe3747b39808
MD5 1606632f15fbf2860d7229a4bfb1ca85
BLAKE2b-256 6ff2276003c3883a959ae1dbc3d7647e9e39055083ddefd6a22d8e33158c180e

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