Tracking Your Heart Rate Via Webcam

I remember being fascinated by the Eulerian Video Magnification work when some of the videos were being spread around, so I was excited to see the Webcam Pulse Detector project pop up on Quantified Self as I was scrolling through some missed feeds this morning.

It didn’t seem too difficult to setup for somebody with some linux familiarity and I set off to make it happen on my laptop.

The entire process took a couple hours. Some of that was due to missteps in installing OpenCV or not using sudo in the right place. The rest was due to the unavoidable—some packages just take a long time to install.

Seeing it finally work is really, really cool. Using my forehead, the app seemed to consistently track my heart rate at around 54-57bpm. At the same time I measured my pulse at my wrist as 60bm. I’ll need to track the consistency over time and with non-resting heart rates as well, but that seems like an acceptable variance so far. Pretty cool stuff.

If you want to give it a go and you’re running OS X 10.8.3 on your machine, I’m embedding a gist with the commands I had to use to make this work along with some comments inline.

# Starting with...
# OS X 10.8.3
# python 2.7.2 // python --version
# c++ 4.0      // c++ --version
# g++ 4.2      // g++ --version
# Update/Install XCode command line utils
# c++ 4.2      // c++ --version
# Doing all my work in ~/Development
cd ~/Development

# Update brew packages
brew update

# Install Python Package Index
sudo easy_install pip

# Install NumPy - was already installed for me
sudo pip install numpy

# Verify that NumPy is available to Python
import numpy
# Would see a file import error if not successful

# SciPy requires a Fortran compiler, available via brew
brew install gfortran

# Install SciPy
sudo pip install scipy

# Verify that SciPy is available to Python
import scipy
# Would see a file import error if not successful

# Install matplotlib
sudo pip install matplotlib

# OpenCV 2.4.5
# Download tar file for Mac/Linux from
# to ~/Development
tar -xvf opencv-2.4.5.tar.gz
cd opencv-2.4.5
mkdir release
cd release
make install

# OpenCV was still not available to Python until I added
# it to the PYTHONPATH variable

# Verify that cv2 is available to Python
import cv2
# Would see a file import error if not successful

# OpenMDAO 0.6.0
# Download from
# to ~/Development

# Clone Webcam Pulse Detector repo
git clone git://

# Launch OpenMDAO terminal
. openmdao-0.6.0/bin/activate

# Launch Webcam Pulse Detector
cd webcam-pulse-detector

There were also plenty of resources that proved invaluable in actually finding the right answers for installing some of these software packages:

Leave a Reply