• Stars
    star
    3,093
  • Rank 14,540 (Top 0.3 %)
  • Language
    Python
  • License
    Other
  • Created over 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A python application that detects and highlights the heart-rate of an individual (using only their own webcam) in real-time.

Alt text

webcam-pulse-detector

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

Stand-alone (no dependancy) precompiled application:

  • Download for Windows 7 and 8: webcam-pulse-detector_win.zip (42 Mb)
  • Download for Mac OSX 10.6 (and later): webcam-pulse-detector_mac.zip (21 Mb)
  • Debian/Ubuntu/Mint Linux: Coming very soon. For now, it is recommended that you run from source on the no_openmdao branch if you just want to test things out.

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:

  • run get_pulse.py to start the application
python get_pulse.py
  • To run on an IP camera, set the url, user, and password strings on line 134 of get_pulse_ipcam.py, then run:
python get_pulse_ipcam.py

This was tested on a Wowwee Rovio.

  • If there is an error, try running test_webcam.py in the same directory to check if your openCV installation and webcam can be made to work with this application.

Usage notes:

  • When run, a window will open showing a stream from your computer's webcam
  • When a forehead location has been isolated, the user should press "S" on their keyboard to lock this location, and remain as still as possible (the camera stream window must have focus for the click to register). This freezes the acquisition location in place. This lock can be released by pressing "S" again.
  • To view a stream of the measured data as it is gathered, press "D". To hide this display, press "D" again.
  • The data display shows three data traces, from top to bottom:
    1. raw optical intensity
    2. extracted heartbeat signal
    3. Power spectral density, with local maxima indicating the heartrate (in beats per minute).
  • With consistent lighting and minimal head motion, a stable heartbeat should be isolated in about 15 to 20 seconds. A count-down is shown in the image frame.
  • If a large spike in optical intensity is measured in the data (due to motion noise, sudden change in lighting, etc) the data collection process is reset and started over. The sensitivity of this feature can be tweaked by changing data_spike_limit on line 31 of get_pulse.py. Other mutable parameters of the analysis can be changed here as well.

More Repositories

1

Python-Arduino-Command-API

A Python library for communicating with Arduino microcontroller boards
Python
406
star
2

stl_tools

Python code to produce STL geometry files from plain text, LaTeX code, and 2D numerical arrays (matrices)
Python
253
star
3

game-of-life

Simple Python implementation of Conway's game of life and other cellular automata, computed using numpy.fft
Python
172
star
4

simple-cython-example

A small project template that shows how to wrap C code into python using cython, along with other packaging concepts
Python
123
star
5

examgen

A Python class that can automatically generate mathematics exams, with solution keys, using Sympy and LaTeX.
Python
53
star
6

math-genealogy

A python script to collect data from the mathematics genealogy project and generate genealogy graphs, combine graphs, etc.
Python
34
star
7

magiceye-solver

A python code to automatically "solve" magic eye autostereograms
Python
30
star
8

pyemotiv

A Python library for data acquisition from the Emotiv Epoc EEG headset, using the research SDK.
Python
22
star
9

pygmaps-extended

Python wrapper for Google Maps JavaScript API V3 and Google Earth API.
Python
16
star
10

github-auto-tools

Python command line tool to clone all public repos and gists from a single github account, and populate empty new repos with a set of templated default files.
Python
15
star
11

pandemic

Python based dynamical optimization of a pandemic disease model
Python
11
star
12

python-screenshot

Python library to make screen captures and save the images to the cwd
Python
11
star
13

pyneulog

Python interface for Neulog GSR sensor
Python
8
star
14

maximum-submatrix-sum

Python code that implements an algorithm for finding the maximum submatrix sum of an M by N matrix
Python
5
star
15

pyrovio

Python code to interface with the Wowwee Rovio robotic webcam
Python
4
star
16

garage_door_control

Android, spark firmware, and fritzing file for garage door control project
Java
4
star
17

Rimworld_roof_editor

Tool for editing roof-types on Rimworld maps
Python
4
star
18

latex-homework-template

A multi-column, landscape-oriented LaTeX template for homework assignments
3
star
19

imresize

A replacement for scipy.misc.imresize that does not depend on PIL
Python
3
star
20

opencv-data-plotter

A python code for fast, real-time 2d data plotting for codes that already have opencv as a dependency.
Python
2
star
21

Atlas

OpenMDAO implementation of the Aerovelo Atlas human-powered helicopter design problem
C
2
star
22

data-store

Some python tools for doing key-value storing
Python
2
star
23

SGNDI

Separable Grid N-Dimensional Interpolator: A multi-dimensional interpolating class with based on 1D interpolation.
Python
2
star
24

CVtemplate

Template for a real time computer vision project using OpenCV
Python
2
star
25

talk_inverse_probs

A short talk on discrete ill-posed inverse problems
Python
2
star
26

arduino-sketch-demos

A collection of various arduino demo sketches
Processing
2
star
27

SwiftFiniteDifference.playground

experimentation with first class functions in Swift
Swift
2
star
28

quick_imshow

Python code to quickly display an image with matplotlib. Meant for debugging image processing code.
Python
2
star
29

CADRE-old

OpenMDAO implementation of the CADRE CubeSat design problem
Python
1
star
30

thearn.github.io

1
star
31

printable_ramps

IPython Notebook for generating hand-drawn 3D-printable candidate solutions to the Brachistochrone problem
JavaScript
1
star
32

pathfinding

Python
1
star
33

android_tutorial

Java
1
star
34

pickle-gzip

Small python library to save and load objects with pickle from disc, with gzip compression.
Python
1
star
35

solar

OpenMDAO solar energy model
Python
1
star