Comment 2 for bug 1563056

Revision history for this message
danjjl (danjjl) wrote :

I was playing around with my Ubuntu Touch phone and python. I wrote a little scripts that calculates the heart rate from a video of my thumb captured on my phone.

For the moment it is a python script but it could probably be used as a base for a C++ equivalent code that could be used in Pulse.

The script and sample data is available at https://github.com/danjjl/pulse

The script can calculate the pulse using two different methods (FFT, spike detection). The script works like this:

 1. Calculate brightness on each frame (mean value over each pixel and RGB channel)
 2. Remove baseline fluctuations using the Asymmetric Least Squares Smoothing

    3a. FFT method
       * calculate FFT of signal
       * find frequency corresponding to maximum FFT coefficient
       * Heart rate is given by maximum FFT frequency * 60

    3b. Spike detector
       * count positive amplitude spikes (and calculate spike occurrence [spikes/minute])
       * count negative amplitude spikes (and calculate spike occurrence [spikes/minute])
       * Heart rate is given by the average of the positive and negative spike occurrence

The script processes the file `thumb.mp4` which is a video **taken without sound** from my phone with the flash on.

The current dependencies are imageio(mp4 processing), scipy, numpy (and matplotlib for figures)

Raw data is quite clean and results seem quite accurate (not validated in any way)

(for the moment I do not have time to convert this script to C++ - but I might find time in August)