Tata Hackathon Project | Submission for Edge AI for ADAS and Autonomous Systems
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.
| 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 |
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
Webcam Feed โ MediaPipe FaceMesh โ EAR / MAR / Head Pose โ Driver State Classification
Driver States:
ATTENTIVEโ Eyes open, looking forwardBLINKโ Short eye closure (< 300ms)DROWSYโ Eyes closed โฅ 2 secondsUNRESPONSIVEโ 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%)
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
- 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
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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 |
- 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
- CARLA Simulator 0.9.13+ running on
localhost:2000 - Python virtual environment (recommended)
git clone https://github.com/priyachaudhary4/SmartVehicleEmergencySystem.git
cd SmartVehicleEmergencySystempython -m venv yolo_env
yolo_env\Scripts\activatepip install carla
pip install opencv-python
pip install mediapipe
pip install ultralytics
pip install scipy
pip install numpy
pip install pyttsx3
pip install flaskLaunch CARLA before running the system:
# From your CARLA installation directory
CarlaUE4.exe -quality-level=Low -windowed -ResX=1280 -ResY=720CARLA must be running on
localhost:2000
python main.py| 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 |
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 # โ DISTRACTEDTraffic 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 distanceThe 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)
Built for the Tata Hackathon by Team GuardianDrive.
This project is developed for hackathon purposes. All simulator assets belong to their respective owners (CARLA, Ultralytics YOLOv8).