Skip to content

mdalmas/RpiDrowsyDriver

Repository files navigation

Drowsiness detection with OpenCV on Raspberry Pi.

Drowsy Driver Detection Using Raspberry Pi and Pi cam

NOTE

This code can be run on laptop webcam , but It is intended to be used on Respberry Pi with Picam Module.

Prerequisites

numpy
dlib
imultis(to test it in pc)
OpenCv ( a tedious task to install it on rpi)
picamera
Rpi.GPIO if you need a alarm/buzzer

Details

  1. The drowsiness detector algorithm:

    1. Search for face. In the camera Stream
      Example Easy Face Detection
    2. If a face is found, we apply facial landmark detection and extract the eye regions.
    3. Now that we have the eye regions, we can compute the eye aspect ratio. If it is less than the a
      certain threshold for a certain number of frames then we trigger the alarm. Example 2 Eye Aspect Ratio Plot
  2. Calculating Eyes Aspect Ratios

    1. The Haar cascade with 68 landmarks Face detector will give us Coordinates for the eye regeion. Example 3 Facilal
    2. we can then use euclidean distance to calculate the 2 vertical and 1 horizontal distance.
  3. Detecting Drowsiness Details

    1. After getting EAR
     if ear < EYE_AR_THRESH:
         COUNTER += 1			
     		if COUNTER >= EYE_AR_CONSEC_FRAMES:
     			# if the alarm is not on, turn it on
     			if not ALARM_ON:
     				ALARM_ON = True  
    
  4. RESULT

    1. This is by no means perfect,
      but combine it with pressure sensors on the steering and we may get a production class safety device.
    2. Demonstration
      The low res video

Using

python pi_detect_drowsiness.py --cascade haarcascade_frontalface_default.xml --shape-predictor shape_predictor_68_face_landmarks.dat --alarm 1

About

Drowsy/Sleepy Driver Detection Using Raspberry Pi and Pi Camera.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages