By Brandon Jackson
Project started December 2012
nap-alert was built using the OpenCV framework.
How It Works
Microsleep strikes quickly. You probably don't even realize you're in the process of falling asleep, and almost certainly don't notice that you are blinking for longer than usual. nap-alert uses your computer's webcam to monitor your blink rate and average blink duration. If your eyes stay closed for long periods of time, then the program lets you know that a nap is imminent. Research indicates that this is one of the most effective ways to predict impending microsleep. For a good review of recent experimental findings, see Caffier et al.
nap-alert should work on any OSX, Linux or Windows system with an OpenCV-compatible webcam. OpenCV maintains a list of these cameras here.
The code was run with OpenCV 2.4.3 and Python 2.7 The following python modules should be downoaded and installed: numpy (version 1.7.0) Python Imaging Library PIL (free version 1.1.7)
- Webcam initialized, capture size scaled down for speed
BlinkStatsclasses are initialized. These classes synthesize information from multiple frames into a more complete picture.
- Controller Loop:
- The highest-level
whileloop which initiates each frame of image capture
- On each new frame the following information is gathered and sent to the
BlinkStatsclass (see below):
- runs the image processing loop (see below) which returns a guess as to whether the image captures a blink event and a reliability indicator
- measures the time that has elapsed since the last frame
- The highest-level
- The Image Processing Loop: each new frame from the webcam goes through the following steps of processing.
FaceDetectorscans the image for faces and eyes, and returns a set of rectangles using Haar Cascade Classifiers.
FaceModelintegrates data from the new frame into a model that keeps track of where the eyes are. To do this it uses:
- A moving average of the most recent frames
- Facial geometry to fill in missing data The resulting model generates a set of two specific regions of interest (ROI's) where blinking is expected to take place.
BlinkDetectorwatches the blinking ROI for blinking. Detection uses a variety of techniques:
- If eye rectangles suddenly disappear and then quickly reappear, this is interpreted as a blink. This method only used when signal quality is very high, to prevent false positives.
- @todo Watches for increase increased brightness in red channel of ROI, caused by the presence of more red pigment in the eyelid than in the eye itself.
- @todo Tracks rapid motion in the ROI The class returns a guess as to whether the current frame captures a blink event, along with a signal quality / confidence / reliability indicator
BlinkStatsreceives blink, time and reliability information and does high-level analysis:
- keeps track of blink event durations and inter-blink intervals
- determines how much weight to give to blink event based on reliability metric
- finds larger-scale blink trends, such as a slow ramping up of blink duration that corresponds to increasing sleepiness
BlinkStatsfinds dangerous trends, the app broadcasts a NAP ALERT!
- Designed and tested using the iSight camera of a 15" Late 2011 Macbook Pro