thearn / webcam-pulse-detector

A python application that detects and highlights the heart-rate of an individual (using only their own webcam) in real-time.
Other
3.14k stars 592 forks source link

Alt text

webcam-pulse-detector

- UPDATE: Now with Python 3.5+ and OpenCV 3.0+ support

Stand-alone (no dependancy) precompiled application:

The application can be run by simply executing the binary contained in the zip file for your platform. This code can also be run from source by following the instructions below.


A python code that detects the heart-rate of an individual using a common webcam or network IP camera. Tested on OSX, Ubuntu, and Windows.

How it works:

This application uses OpenCV to find the location of the user's face, then isolate the forehead region. Data is collected from this location over time to estimate the user's heart rate. This is done by measuring average optical intensity in the forehead location, in the subimage's green channel alone (a better color mixing ratio may exist, but the blue channel tends to be very noisy). Physiological data can be estimated this way thanks to the optical absorption characteristics of (oxy-) haemoglobin (see http://www.opticsinfobase.org/oe/abstract.cfm?uri=oe-16-26-21434).

With good lighting and minimal noise due to motion, a stable heartbeat should be isolated in about 15 seconds. Other physiological waveforms (such as Mayer waves) should also be visible in the raw data stream.

Once the user's heart rate has been estimated, real-time phase variation associated with this frequency is also computed. This allows for the heartbeat to be exaggerated in the post-process frame rendering, causing the highlighted forehead location to pulse in sync with the user's own heartbeat.

Support for detection on multiple simultaneous individuals in a single camera's image stream is definitely possible, but at the moment only the information from one face is extracted for analysis.

The overall dataflow/execution order for the real-time signal processing looks like:

Alt text

Requirements:

Quickstart:

python get_pulse.py
python get_pulse_ipcam.py

This was tested on a Wowwee Rovio.

Usage notes: