AI-powered drowsiness detection library for driver safety
Project description
๐ SleepyDriver - AI ๊ธฐ๋ฐ ์กธ์ ๊ฐ์ง ๋ผ์ด๋ธ๋ฌ๋ฆฌ
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/*
๐ค ๊ธฐ์ฌํ๊ธฐ
- Fork ์ ์ฅ์
- ๊ธฐ๋ฅ ๋ธ๋์น ์์ฑ (
git checkout -b feature/amazing-feature) - ๋ณ๊ฒฝ์ฌํญ ์ปค๋ฐ (
git commit -m 'Add amazing feature') - ๋ธ๋์น ํธ์ (
git push origin feature/amazing-feature) - Pull Request ์์ฑ
๐ ๋ผ์ด์ ์ค
์ด ํ๋ก์ ํธ๋ MIT ๋ผ์ด์ ์ค ํ์ ๋ฐฐํฌ๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ์ LICENSE ํ์ผ์ ์ฐธ์กฐํ์ธ์.
๐ ๊ฐ์ฌ์ ๋ง
- MediaPipe - ์ผ๊ตด ๋๋๋งํฌ ๊ฐ์ง
- OpenCV - ์ปดํจํฐ ๋น์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- PyTorch - ๋ฅ๋ฌ๋ ํ๋ ์์ํฌ
- scikit-learn - ๋จธ์ ๋ฌ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๐ ์ง์ ๋ฐ ๋ฌธ์
- ๐ ๋ฌธ์: sleepy-driver.readthedocs.io
- ๐ ๋ฒ๊ทธ ๋ฆฌํฌํธ: GitHub Issues
- ๐ฌ ๋์ค์ปค์ : GitHub Discussions
- ๐ง ์ด๋ฉ์ผ: sleepy.driver@example.com
โ ๏ธ ์ฃผ์์ฌํญ: ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ณด์กฐ ๋๊ตฌ๋ก๋ง ์ฌ์ฉํ์ธ์. ์ค์ ์ด์ ์์๋ ํญ์ ์์ ์ ์ต์ฐ์ ์ผ๋ก ํ๊ณ , ์กธ์์ ๋๋ผ๋ฉด ์ฆ์ ์์ ํ ๊ณณ์ ์ ์ฐจํ์ฌ ํด์์ ์ทจํ์ธ์.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35a08d228a0e4bad7e836ad0954cf5cb045844a5a1a7bac77161e6137f68ec19
|
|
| MD5 |
42bb4b56178f750580f0f7f943ec5eba
|
|
| BLAKE2b-256 |
f4ffa7e9caec39458bf2f86eee6aaa5f91c465ed5badf7abcdbad1eafb6d1294
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c96f0c90d0eede14b0bc5d23f04b353d269bc1ba846c822633b16106cdda10c
|
|
| MD5 |
5d7e2a72b81bc2c2b06d7bba765b71d1
|
|
| BLAKE2b-256 |
722df837817981600a4a828ed9c9fef60acd52f7613415327be11df27240b4b3
|