Skip to content

SametGundz/DriveSafe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

52 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš— Real Time Driver Drowsiness and Distraction Detection System

Python PyQt6 MediaPipe License

GUI Gaze Zones


๐Ÿš€ Installation

๐Ÿ”ง 1. Installing Required Packages

# Clone the repository
git clone https://github.com/username/driver-drowsiness.git
cd driver-drowsiness

# Create a virtual environment (recommended)
python -m venv venv

# Activate the virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install required packages
pip install -r requirements.txt

๐Ÿค– 2. Downloading the ETH-XGaze Model

The ETH-XGaze model is not included in the repository due to its large size. Follow these steps:

Option A: Official Model (Recommended)

  1. Visit the ETH-XGaze official page
  2. Download the model file (epoch_24_ckpt.pth.tar)
  3. Place it in the models/ directory:
    mkdir -p models
    # Copy the downloaded file to the models directory
    cp /download/path/epoch_24_ckpt.pth.tar models/eth_xgaze_model.pth

Option B: ONNX Format (Fast Inference)

# Run the model conversion script
python scripts/convert_ethxgaze_model.py models/eth_xgaze_model.pth models/eth_xgaze_model.onnx --export_onnx

๐Ÿ’ป Usage

๐ŸŽฎ 1. Basic Usage

# Start the main application
python run.py

Usage Steps:

  1. ๐ŸŽฅ Make sure your camera is connected
  2. โ–ถ๏ธ Click the "Start" button
  3. ๐Ÿ‘ค Keep your face in the camera's field of view
  4. ๐Ÿ“Š Monitor real-time metrics
  5. โน๏ธ End the analysis with "Stop"

๐Ÿ“น 2. Video Analysis

# Video file analysis
python examples/analyze_video.py --input video.mp4 --output results/

# Batch video analysis
python scripts/batch_analyze.py --input_dir videos/ --output_dir results/

Video Upload

๐ŸŽฏ 3. Gaze Zone Detection

# Gaze zone test
python tests/test_gaze_zone_detector.py --camera 0 --show_zones

# Gaze zone calibration
python scripts/calibrate_gaze_zones.py

Classification Performance Metrics

Classification Performance Metrics

  • Overall Accuracy: 93.23%
  • Balanced Accuracy: 83.70%
  • Macro-averaged Precision: 91.96%
  • Macro-averaged Recall: 83.70%
  • Macro-averaged F1-Score: 85.84%

Statistical Reliability Measures

  • Cohen's Kappa: 0.9110 (Almost Perfect)
  • Matthews Correlation Coefficient: 0.8549
  • Krippendorff's Alpha: 0.9110

๐Ÿ“Š Scientific Metrics

๐Ÿ‘๏ธ EAR (Eye Aspect Ratio)

  • Formula: EAR = (|p2-p6| + |p3-p5|) / (2 * |p1-p4|)
  • Threshold Value: 0.21 (eyes considered closed below this)
  • Usage: Instant eye blink and closure detection

๐Ÿ‘„ MAR (Mouth Aspect Ratio)

  • Formula: MAR = |p14-p18| / |p12-p16|
  • Threshold Value: 0.65 (mouth considered open above this)
  • Usage: Yawning detection

๐Ÿ’ค PERCLOS

  • Definition: Percentage of eye closure over a 60-second period
  • Warning Threshold: 15%
  • Critical Threshold: 20%

๐Ÿ˜ด KSS (Karolinska Sleepiness Scale)

Score Status Description
1-3 ๐ŸŸข Normal Fully awake state
4-5 ๐ŸŸก Mild Mild signs of fatigue
6-7 ๐ŸŸ  Warning Beginning of attention deficit
8-9 ๐Ÿ”ด Critical Immediate intervention required

๐Ÿ”ฌ Advanced Features

๐ŸŽญ 3D Head Pose Visualization

  • Real-time 3D Model: Real-time head pose visualization
  • Pitch/Yaw/Roll: Three-axis rotation tracking
  • Interactive Controls: User-controlled view settings
# 3D model usage example
from src.ui.head_pose_model import Head3DPanel

head_panel = Head3DPanel()
head_panel.update_pose(pitch=10, yaw=-5, roll=2)

๐Ÿ“ Gaze Zone Detection

EU regulation C(2023)4523 compliant 9 zones:

Zone ID Zone Name Area Criticality
0 Road Center Area 2 ๐Ÿ”ด Critical
1 Driving Instruments Area 2 ๐ŸŸก Driving Related
2 Infotainment Area 1 ๐ŸŸ  Non-Driving
3 Left Side Area 2 ๐ŸŸก Driving Related
4 Right Side Area 2 ๐ŸŸก Driving Related
5 Rear Mirror Area 2 ๐Ÿ”ด Critical

๐Ÿงช Testing and Evaluation

๐Ÿ”ฌ Scientific Evaluation

# Precision/Recall analysis
python scripts/scientific_evaluation.py \
  --ground_truth data/gt.json \
  --predictions data/pred.json \
  --output_dir evaluation_results/

Classification Performance Metrics

Most Frequent Confusion Pairs:
  • Zones 4โ†”5: 36 errors (2.32%)
  • Zones 1โ†”2: 21 errors (1.35%)
  • Zones 2โ†”4: 14 errors (0.90%)

Classification Performance Metrics

Critical Zone Performance:

  • Critical Zone Accuracy: 85.82%
  • Safety Impact Score: 14.18%

CONCLUSIONS AND RECOMMENDATIONS

  • Excellent classification performance achieved (>90% accuracy)
  • Almost perfect inter-rater agreement demonstrated

๐Ÿ”ฌ Scientific References