Skip to main content

AI-powered drowsiness detection library for driver safety

Project description

๐Ÿš— SleepyDriver - AI ๊ธฐ๋ฐ˜ ์กธ์Œ ๊ฐ์ง€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

PyPI version Python License: MIT

SleepyDriver๋Š” ์‹ค์‹œ๊ฐ„ ๋น„๋””์˜ค์—์„œ ์šด์ „์ž์˜ ์กธ์Œ ์ƒํƒœ๋ฅผ AI๋กœ ๊ฐ์ง€ํ•˜๋Š” ํŒŒ์ด์ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. 4๊ฐ€์ง€ ๋‹ค์–‘ํ•œ ๊ฐ์ง€ ๋ชจ๋ธ์„ ์ง€์›ํ•˜๋ฉฐ, ๊ฐ„๋‹จํ•œ API๋กœ ํ”„๋กœ์ ํŠธ์— ์‰ฝ๊ฒŒ ํ†ตํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

โœจ ์ฃผ์š” ๊ธฐ๋Šฅ

  • ๐ŸŽฏ 4๊ฐ€์ง€ ๊ฐ์ง€ ๋ชจ๋ธ: OpenCV, ๋จธ์‹ ๋Ÿฌ๋‹(RF), ๋”ฅ๋Ÿฌ๋‹(CNN), MediaPipe ๊ธฐ๋ฐ˜
  • โšก ์‹ค์‹œ๊ฐ„ ์ฒ˜๋ฆฌ: ์›น์บ ์—์„œ ์‹ค์‹œ๊ฐ„ ์กธ์Œ ๊ฐ์ง€ (~30 FPS)
  • ๐Ÿ”ง ๊ฐ„๋‹จํ•œ API: 3์ค„์˜ ์ฝ”๋“œ๋กœ ์กธ์Œ ๊ฐ์ง€ ์‹œ์Šคํ…œ ๊ตฌ์ถ•
  • ๐Ÿ“ฆ ํ”Œ๋Ÿฌ๊ทธ์ธ ์•„ํ‚คํ…์ฒ˜: ์‚ฌ์šฉ์ž ์ •์˜ ๋ชจ๋ธ ์‰ฝ๊ฒŒ ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
  • ๐Ÿ›ก๏ธ ์•ˆ์ •์„ฑ: ๊ฐ•๋ ฅํ•œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ์™€ ์˜์กด์„ฑ ๊ด€๋ฆฌ
  • ๐Ÿ–ฅ๏ธ CLI ์ง€์›: ์„ค์น˜ ํ›„ ๋ฐ”๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ช…๋ นํ–‰ ๋„๊ตฌ

๐Ÿš€ ๋น ๋ฅธ ์‹œ์ž‘

์„ค์น˜

# ๊ธฐ๋ณธ ์„ค์น˜ (OpenCV ๋ชจ๋ธ๋งŒ)
pip install sleepy-driver

# ๋ชจ๋“  ๋ชจ๋ธ ํฌํ•จ ์„ค์น˜ (๊ถŒ์žฅ)
pip install sleepy-driver[all]

# ์„ ํƒ์  ์„ค์น˜
pip install sleepy-driver[ml]    # ๋จธ์‹ ๋Ÿฌ๋‹ ๋ชจ๋ธ
pip install sleepy-driver[dl]    # ๋”ฅ๋Ÿฌ๋‹ ๋ชจ๋ธ

CLI๋กœ ๋ฐ”๋กœ ์‚ฌ์šฉ

# ๊ธฐ๋ณธ ์‹คํ–‰
sleepy-driver-demo

# ๋‹ค๋ฅธ ๋ชจ๋ธ๋กœ ์‹คํ–‰
sleepy-driver-demo --model mlp --threshold 2000

# ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋ธ ํ™•์ธ
sleepy-driver-demo --list-models

์ฝ”๋“œ๋กœ ์‚ฌ์šฉ (์ดˆ๊ฐ„๋‹จ!)

๐Ÿš€ ์›๋ผ์ด๋„ˆ (๊ฐ€์žฅ ๊ฐ„๋‹จ!)

# 1์ค„๋กœ ๋ฐ”๋กœ ์‹œ์ž‘!
from sleepy_driver import start_detection
start_detection()  # ๊ธฐ๋ณธ OpenCV ๋ชจ๋ธ๋กœ ๋ฐ”๋กœ ์›น์บ  ๊ฐ์ง€ ์‹œ์ž‘

# ๋ชจ๋ธ ์„ ํƒํ•ด์„œ ์‹œ์ž‘
start_detection('mlp')  # MLP ๋ชจ๋ธ๋กœ ๋ฐ”๋กœ ์‹œ์ž‘
start_detection('ml', threshold_ms=2000)  # ML ๋ชจ๋ธ, 2์ดˆ ์ž„๊ณ„๊ฐ’

๐Ÿ“ ์ง์ ‘ ์ œ์–ดํ•˜๊ธฐ

from sleepy_driver import quick_detector
import cv2

# 1์ค„๋กœ ๊ฐ์ง€๊ธฐ ์ƒ์„ฑ
detector = quick_detector('opencv')

# ์›น์บ ์—์„œ ์‹ค์‹œ๊ฐ„ ๊ฐ์ง€
cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read()

    # 1์ค„๋กœ ์กธ์Œ ๊ฐ์ง€!
    result = detector.detect(frame)

    if result.is_drowsy:
        print(f"๐Ÿ˜ด ์กธ์Œ ๊ฐ์ง€! {result.closed_duration_ms}ms")

๐Ÿ“‹ ์ง€์› ๋ชจ๋ธ

๋ชจ๋ธ ์„ค๋ช… ์žฅ์  ์˜์กด์„ฑ
opencv OpenCV ๊ธฐ๋ฐ˜ ์ „ํ†ต์  ์ปดํ“จํ„ฐ ๋น„์ „ ๋น ๋ฆ„, ์˜์กด์„ฑ ์ ์Œ ์—†์Œ
ml RandomForest ๋จธ์‹ ๋Ÿฌ๋‹ ๊ท ํ˜•์žกํžŒ ์„ฑ๋Šฅ scikit-learn
mlp CNN ๋”ฅ๋Ÿฌ๋‹ ๋†’์€ ์ •ํ™•๋„ PyTorch
point MediaPipe ๋žœ๋“œ๋งˆํฌ ์‹ค์‹œ๊ฐ„์„ฑ ์šฐ์ˆ˜ ์—†์Œ

๐Ÿ’ก ๊ณ ๊ธ‰ ์‚ฌ์šฉ๋ฒ•

์ปค์Šคํ…€ ์„ค์ •

from sleepy_driver import DrowsinessDetector, TimeBased
from sleepy_driver.models import OpenCVEyeModel

# ์ง์ ‘ ๊ตฌ์„ฑ
eye_model = OpenCVEyeModel()
analyzer = TimeBased(threshold_ms=1500)  # 1.5์ดˆ ์ž„๊ณ„๊ฐ’

detector = DrowsinessDetector.create_with_custom_components(
    eye_model=eye_model,
    drowsiness_analyzer=analyzer
)

๊ฒฐ๊ณผ ๋ถ„์„

result = detector.detect(frame)

print(f"์„ฑ๊ณต: {result.success}")
print(f"์กธ์Œ ์ƒํƒœ: {result.is_drowsy}")
print(f"๋ˆˆ ๊ฐ์€ ์‹œ๊ฐ„: {result.closed_duration_ms}ms")
print(f"์ขŒ/์šฐ ๋ˆˆ ์ƒํƒœ: {result.left_eye_closed}, {result.right_eye_closed}")
print(f"์‹ ๋ขฐ๋„: {result.confidence}")

์‚ฌ์šฉ์ž ์ •์˜ ๋ชจ๋ธ

from sleepy_driver.models.base import EyeStateDetector

class MyCustomModel(EyeStateDetector):
    def initialize(self) -> bool:
        # ๋ชจ๋ธ ์ดˆ๊ธฐํ™”
        return True

    def detect_eye_state(self, eye_image) -> tuple[bool, float]:
        # ์—ฌ๊ธฐ์— ๋‹น์‹ ๋งŒ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„
        is_closed = your_algorithm(eye_image)
        confidence = 0.95
        return is_closed, confidence

# ์‚ฌ์šฉ
detector = DrowsinessDetector.create_with_custom_components(
    eye_model=MyCustomModel()
)

๐ŸŽฏ ์‹ค์ œ ํ”„๋กœ์ ํŠธ ํ†ตํ•ฉ

์›น ์„œ๋น„์Šค ํ†ตํ•ฉ

from flask import Flask, Response
from sleepy_driver import quick_detector
import cv2

app = Flask(__name__)
detector = quick_detector('mlp')

@app.route('/drowsiness_check', methods=['POST'])
def check_drowsiness():
    # ์ด๋ฏธ์ง€ ๋ฐ›์•„์„œ ์กธ์Œ ๊ฐ์ง€
    result = detector.detect(image)
    return {
        'is_drowsy': result.is_drowsy,
        'duration_ms': result.closed_duration_ms,
        'confidence': result.confidence
    }

IoT/์ž„๋ฒ ๋””๋“œ ์‹œ์Šคํ…œ

import RPi.GPIO as GPIO
from sleepy_driver import quick_detector

detector = quick_detector('opencv')  # ๊ฐ€๋ฒผ์šด ๋ชจ๋ธ
buzzer_pin = 18

def drowsiness_alert():
    GPIO.output(buzzer_pin, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(buzzer_pin, GPIO.LOW)

# ์‹ค์‹œ๊ฐ„ ๊ฐ์ง€
while True:
    result = detector.detect(frame)
    if result.is_drowsy:
        drowsiness_alert()

๐Ÿ“Š ์„ฑ๋Šฅ ๋ฒค์น˜๋งˆํฌ

๋ชจ๋ธ ํ‰๊ท  FPS ์ •ํ™•๋„ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰
OpenCV ~35 FPS 85% ~50MB
ML (RF) ~30 FPS 90% ~100MB
MLP (CNN) ~28 FPS 95% ~200MB
Point ~40 FPS 80% ~30MB

ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ: MacBook Pro M1, 720p ์›น์บ 

๐Ÿ› ๏ธ ๊ฐœ๋ฐœ์ž ๊ฐ€์ด๋“œ

๋กœ์ปฌ ๊ฐœ๋ฐœ ์„ค์ •

# ์ €์žฅ์†Œ ํด๋ก 
git clone https://github.com/sleepy-driver/sleepy-driver.git
cd sleepy-driver

# ๊ฐœ๋ฐœ ์˜์กด์„ฑ ์„ค์น˜
pip install -e .[dev]

# ํ…Œ์ŠคํŠธ ์‹คํ–‰
pytest tests/

# ์ฝ”๋“œ ํฌ๋งทํŒ…
black sleepy_driver/
flake8 sleepy_driver/

ํŒจํ‚ค์ง€ ๋นŒ๋“œ

# ๋นŒ๋“œ ๋„๊ตฌ ์„ค์น˜
pip install build twine

# ํŒจํ‚ค์ง€ ๋นŒ๋“œ
python -m build

# PyPI ์—…๋กœ๋“œ (๊ด€๋ฆฌ์ž๋งŒ)
twine upload dist/*

๐Ÿค ๊ธฐ์—ฌํ•˜๊ธฐ

  1. Fork ์ €์žฅ์†Œ
  2. ๊ธฐ๋Šฅ ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ (git checkout -b feature/amazing-feature)
  3. ๋ณ€๊ฒฝ์‚ฌํ•ญ ์ปค๋ฐ‹ (git commit -m 'Add amazing feature')
  4. ๋ธŒ๋žœ์น˜ ํ‘ธ์‹œ (git push origin feature/amazing-feature)
  5. Pull Request ์ƒ์„ฑ

๐Ÿ“„ ๋ผ์ด์„ ์Šค

์ด ํ”„๋กœ์ ํŠธ๋Š” MIT ๋ผ์ด์„ ์Šค ํ•˜์— ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ LICENSE ํŒŒ์ผ์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๐Ÿ™ ๊ฐ์‚ฌ์˜ ๋ง

  • MediaPipe - ์–ผ๊ตด ๋žœ๋“œ๋งˆํฌ ๊ฐ์ง€
  • OpenCV - ์ปดํ“จํ„ฐ ๋น„์ „ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
  • PyTorch - ๋”ฅ๋Ÿฌ๋‹ ํ”„๋ ˆ์ž„์›Œํฌ
  • scikit-learn - ๋จธ์‹ ๋Ÿฌ๋‹ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

๐Ÿ†˜ ์ง€์› ๋ฐ ๋ฌธ์˜


โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋ณด์กฐ ๋„๊ตฌ๋กœ๋งŒ ์‚ฌ์šฉํ•˜์„ธ์š”. ์‹ค์ œ ์šด์ „ ์‹œ์—๋Š” ํ•ญ์ƒ ์•ˆ์ „์„ ์ตœ์šฐ์„ ์œผ๋กœ ํ•˜๊ณ , ์กธ์Œ์„ ๋А๋ผ๋ฉด ์ฆ‰์‹œ ์•ˆ์ „ํ•œ ๊ณณ์— ์ •์ฐจํ•˜์—ฌ ํœด์‹์„ ์ทจํ•˜์„ธ์š”.

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

sleepy_driver-1.1.3.tar.gz (7.8 MB view details)

Uploaded Source

Built Distribution

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

sleepy_driver-1.1.3-py3-none-any.whl (7.8 MB view details)

Uploaded Python 3

File details

Details for the file sleepy_driver-1.1.3.tar.gz.

File metadata

  • Download URL: sleepy_driver-1.1.3.tar.gz
  • Upload date:
  • Size: 7.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for sleepy_driver-1.1.3.tar.gz
Algorithm Hash digest
SHA256 35a08d228a0e4bad7e836ad0954cf5cb045844a5a1a7bac77161e6137f68ec19
MD5 42bb4b56178f750580f0f7f943ec5eba
BLAKE2b-256 f4ffa7e9caec39458bf2f86eee6aaa5f91c465ed5badf7abcdbad1eafb6d1294

See more details on using hashes here.

File details

Details for the file sleepy_driver-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: sleepy_driver-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for sleepy_driver-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3c96f0c90d0eede14b0bc5d23f04b353d269bc1ba846c822633b16106cdda10c
MD5 5d7e2a72b81bc2c2b06d7bba765b71d1
BLAKE2b-256 722df837817981600a4a828ed9c9fef60acd52f7613415327be11df27240b4b3

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