Skip to content

priyachaudhary4/SmartVehicleEmergencySystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšจ GuardianDrive: An AI-Enabled Smart Vehicle Emergency Response System

Tata Hackathon Project | Submission for Edge AI for ADAS and Autonomous Systems


๐Ÿ“– Overview

GuardianDrive is an intelligent in-vehicle emergency response system that uses real-time computer vision and AI to monitor driver health, detect critical conditions (drowsiness, distraction, unresponsiveness), and autonomously take over vehicle control to ensure passenger and public safety.

The system integrates seamlessly with the CARLA autonomous driving simulator and leverages MediaPipe, YOLOv8, and a custom multi-threaded decision engine to provide a complete emergency co-pilot solution.


๐ŸŽฏ Key Features

Feature Description
๐Ÿง  Driver Drowsiness Detection Real-time Eye Aspect Ratio (EAR) & blink monitoring using MediaPipe FaceMesh
๐Ÿ˜ฎ Yawn Detection Mouth Aspect Ratio (MAR) analysis to detect fatigue-induced yawning
๐Ÿ‘€ Head Pose Estimation 6-DOF head pose via PnP solver โ€” detects distraction (looking left, right, up, down)
๐Ÿ“Š Fatigue Scoring Composite fatigue index (0โ€“100%) from eye closure, yawning, blink frequency & head movement
๐Ÿš— Autonomous Takeover AI safely decelerates, applies hazard lights, and brings the vehicle to a stop
๐Ÿš‘ Emergency Dispatch Automatically alerts EMS, Police, emergency contacts, and nearby vehicles (V2V)
๐Ÿ”Š Voice Alerts (TTS) Real-time audio warnings to driver using pyttsx3
๐Ÿšจ Ambulance Spawn Spawns a Ford Ambulance actor in CARLA near the ego vehicle on emergency
๐Ÿšถ V2V Crowd Response Nearby simulated vehicles stop and pedestrians walk towards the emergency scene
๐Ÿ–ฅ๏ธ HUD Dashboard Glassmorphism-style OpenCV dashboard with speedometer, ADAS status, GPS & alert logs

๐Ÿ—๏ธ System Architecture

SmartVehicleEmergencySystem/
โ”‚
โ”œโ”€โ”€ main.py                    # Main orchestration loop & HUD rendering
โ”‚
โ”œโ”€โ”€ ai/                        # Computer Vision AI Modules
โ”‚   โ”œโ”€โ”€ driver_monitor.py      # MediaPipe face mesh, EAR/MAR/head pose
โ”‚   โ”œโ”€โ”€ yolo_detector.py       # YOLOv8 environment object detection
โ”‚   โ”œโ”€โ”€ ear_detection.py       # Eye Aspect Ratio utilities
โ”‚   โ”œโ”€โ”€ eye_detection.py       # Eye landmark detection
โ”‚   โ””โ”€โ”€ face_mesh.py           # Face mesh wrapper
โ”‚
โ”œโ”€โ”€ future/                    # Decision & Control Modules
โ”‚   โ”œโ”€โ”€ emergency_manager.py   # Emergency decision engine & protocol
โ”‚   โ”œโ”€โ”€ vehicle_controller.py  # CARLA vehicle control (autopilot, emergency stop)
โ”‚   โ”œโ”€โ”€ notification_system.py # Alert dispatcher (EMS, police, contacts)
โ”‚   โ””โ”€โ”€ dashboard.py           # Flask/web dashboard thread & shared state
โ”‚
โ”œโ”€โ”€ templates/                 # Web dashboard HTML templates
โ”œโ”€โ”€ yolov8n.pt                 # Pre-trained YOLOv8 nano model weights
โ”œโ”€โ”€ camera_sensor.py           # CARLA camera sensor utilities
โ”œโ”€โ”€ spawn_vehicle.py           # Vehicle spawning helper
โ”œโ”€โ”€ preview_ui.py              # UI preview utilities
โ””โ”€โ”€ requirements.txt           # Python dependencies

๐Ÿงช How It Works

1. Driver Monitoring Pipeline

Webcam Feed โ†’ MediaPipe FaceMesh โ†’ EAR / MAR / Head Pose โ†’ Driver State Classification

Driver States:

  • ATTENTIVE โ€” Eyes open, looking forward
  • BLINK โ€” Short eye closure (< 300ms)
  • DROWSY โ€” Eyes closed โ‰ฅ 2 seconds
  • UNRESPONSIVE โ€” Eyes closed โ‰ฅ 4 seconds (triggers emergency)
  • DISTRACTED โ€” Head turned away > 3 seconds (triggers emergency)
  • FAINTED โ€” Head turned โ‰ฅ 5 seconds (triggers emergency)

Fatigue Score Formula:

Fatigue = (Eye Closure ร— 30%) + (Yawning ร— 30%) + (Blink Freq ร— 20%) + (Head Movement ร— 20%)

2. Emergency Protocol Sequence

UNRESPONSIVE/FAINTED Detected
    โ†’ 3ร— Progressive Voice Warnings (2s apart)
    โ†’ Emergency Takeover:
        [1] Voice alert + Siren (winsound)
        [2] Dispatch notifications (EMS, Police, Contacts, V2V)
        [3] CARLA vehicle: reduce speed โ†’ hazard lights โ†’ safe stop
        [4] Spawn Ambulance actor behind ego vehicle
        [5] Nearby V2V vehicles stop; pedestrians walk to scene

3. Environment Perception (YOLOv8)

  • Third-person CARLA RGB camera feed โ†’ YOLOv8 nano model
  • Detected classes: Cars, Pedestrians, Motorcycles, Traffic Lights, Road Signs, Bicycles, Heavy Vehicles
  • Detection counts updated live in the HUD

๐Ÿ–ฅ๏ธ Dashboard HUD Layout

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  LEFT PANEL (360px)  โ”‚  CENTER (1000px)         โ”‚  RIGHT PANEL (400px)โ”‚
โ”‚                      โ”‚                           โ”‚                     โ”‚
โ”‚  โ€ข Speedometer       โ”‚  CARLA Camera Feed        โ”‚  โ€ข Driver Monitor   โ”‚
โ”‚  โ€ข Throttle/Brake    โ”‚  (YOLOv8 Detections)      โ”‚  โ€ข Driver Status    โ”‚
โ”‚  โ€ข ADAS Status       โ”‚                           โ”‚  โ€ข Fatigue Level    โ”‚
โ”‚  โ€ข Alert Logs        โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€    โ”‚  โ€ข Emergency Info   โ”‚
โ”‚                      โ”‚  Bottom Panel (300px)     โ”‚  โ€ข Health Profile   โ”‚
โ”‚                      โ”‚  โ€ข Objects Summary        โ”‚                     โ”‚
โ”‚                      โ”‚  โ€ข System Alerts          โ”‚                     โ”‚
โ”‚                      โ”‚  โ€ข Comm Status  โ”‚ GPS     โ”‚                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Keyboard Controls:

Key Action
ESC Shutdown system
Q Toggle Autopilot ON/OFF
W Throttle forward
S Reverse
A / D Steer left / right
X Brake
C Center steering

โš™๏ธ Prerequisites

System Requirements

  • OS: Windows 10/11 (64-bit) (winsound dependency)
  • Python: 3.8 โ€“ 3.10
  • GPU: NVIDIA GPU recommended for YOLO inference
  • Webcam: Required for driver monitoring

Software Requirements

  • CARLA Simulator 0.9.13+ running on localhost:2000
  • Python virtual environment (recommended)

๐Ÿš€ Installation & Setup

Step 1 โ€” Clone the Repository

git clone https://github.com/priyachaudhary4/SmartVehicleEmergencySystem.git
cd SmartVehicleEmergencySystem

Step 2 โ€” Create Virtual Environment

python -m venv yolo_env
yolo_env\Scripts\activate

Step 3 โ€” Install Dependencies

pip install carla
pip install opencv-python
pip install mediapipe
pip install ultralytics
pip install scipy
pip install numpy
pip install pyttsx3
pip install flask

Step 4 โ€” Start CARLA Simulator

Launch CARLA before running the system:

# From your CARLA installation directory
CarlaUE4.exe -quality-level=Low -windowed -ResX=1280 -ResY=720

CARLA must be running on localhost:2000

Step 5 โ€” Run the System

python main.py

๐Ÿ“ฆ Key Dependencies

Package Purpose
carla CARLA Python API โ€” simulator connection, vehicle control
opencv-python Camera feed processing, HUD rendering
mediapipe Face mesh landmarks for driver monitoring
ultralytics YOLOv8 object detection
scipy Euclidean distance for EAR/MAR calculation
numpy Numerical array operations
pyttsx3 Text-to-speech voice alerts
winsound System beep/siren alerts (Windows)
flask Web dashboard backend
threading Concurrent emergency protocol execution

๐Ÿ”ง Configuration

Key parameters can be tuned in ai/driver_monitor.py:

EAR_THRESHOLD = 0.20        # Eye Aspect Ratio โ€” below this = eyes closed
MAR_THRESHOLD = 0.60        # Mouth Aspect Ratio โ€” above this = yawning
# Timing thresholds in process_frame():
closed_duration >= 4.0      # โ†’ UNRESPONSIVE
closed_duration >= 2.0      # โ†’ DROWSY
distracted_duration >= 5.0  # โ†’ FAINTED
distracted_duration > 3.0   # โ†’ DISTRACTED

Traffic manager settings in main.py:

tm.vehicle_percentage_speed_difference(vehicle, 0.0)  # 100% speed limit
tm.distance_to_leading_vehicle(vehicle, 8.0)          # 8m following distance

๐Ÿ—บ๏ธ CARLA Map

The system loads Town05 by default:

world = client.load_world('Town05')

Town05 features a multi-lane highway layout suitable for emergency scenario simulation.

Simulation Setup:

  • 40 background NPC vehicles spawned via Traffic Manager
  • Ego vehicle: Tesla Model 3 blueprint
  • Third-person RGB camera: x=-6.5, z=3.2, pitch=-15ยฐ
  • Synchronous mode: fixed_delta_seconds = 0.05 (20 FPS)

๐Ÿค Team

Built for the Tata Hackathon by Team GuardianDrive.


๐Ÿ“„ License

This project is developed for hackathon purposes. All simulator assets belong to their respective owners (CARLA, Ultralytics YOLOv8).

About

๐ŸšจGuardianDrive - AI-powered emergency co-pilot system built on CARLA Simulator : detects driver drowsiness, distraction & unresponsiveness using MediaPipe, then autonomously takes over vehicle control and dispatches emergency alerts.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors