The goal of this project is to create a mobile application that accurately measures the heart rate of a person using the video captured by the front camera of a mobile phone. For this project, we referred to the paper “Validation of heart rate extraction using video imaging on a built-in camera system of a smartphone” presented in 2012 Annual International Conference of the IEEE.
· Development Environment – Android (Supports KitKat, JellyBean, Icecream Sandwich)
· Testing Environment – Android and MATLAB R2014b, R2014a
· Integrated Development Environment – Android Studio, Eclipse
· External Libraries – OpenCV4Android 2.4.9
· Mobile Device – Samsung Galaxy S4
· Camera (Front) - 2 MP, 1080p@30fps
We extract heart rate and beat lengths from video by measuring subtle change in skin color due to the influx of blood at each beat. A camera captures these subtle variations and we extract the heart beat signal from the average pixel intensity value variation and then calculate the heart rate.
In order to achieve this, we have implemented the following steps:
1. Viola Jones Face Detection and Tracking from OpenCV
2. Calculating the average pixel value of Red,Green and Blue Channels of each Frame
3. Cubic Spline Interpolation
4. Temporal Filtering
5. Independent Component Analysis
6. Peak Detection
We are using the “lbpcascade_frontalface.xml” Classifier for the Face Detection. We have downloaded a sample Face Detection and Tracking code from the OpenCV sample code and implemented this in our project.
Figure 1: Face Detection and Tracking
An average person’s heart rate is between 40 and 150 beats per minute that translates to [0.67, 2.5] Hz in the frequency domain. Our frame rate varies in between 10 and 11 frames per second. The authors perform interpolation on their signal to obtain a 250 Hz signal.
Figure 2: Cubic Spline Interpolation
Due to the hardware constraints of a mobile device, we could perform a Cubic Spline Interpolation by a factor of 2. Therefore, our samples improved from 10-11 frames per second to 20-22 frames per second.
We are implementing a Band-Pass Filter because the low and high-frequency components of the signal negatively impacts the heart rate response. For this, we are implementing a 5th Order Butterworth Band-Pass Filter with a pass band of [0.75, 5] Hz. In order to achieve better results, we are using the filter coefficients that are generated using MATLAB. To improve the computational efficiency of the mobile device, these filter coefficients ‘a’ and ‘b’ have been generated in the Sampling Frequency range of 20 Hz to 22 Hz and with a pass band of [0.75, 5] Hz using MATLAB.
Figure 3: 5th Order Butterworth Filter Response
In the above figure, as there are no frequency components above and below the threshold, the response is the same.
The underlying source signal of interest is the variation of “Average Skin Color” value caused by the cardiovascular pulse. Whereas the average skin color value is a mixture of signals emanating from various other sources e.g. Varying Lighting Conditions. We must decompose this mixed motion into sub-signals to isolate the pulse.
Since we have 3 signals (the Red, Green and Blue Channels) to work with, we need to calculate the most periodic signal that relates to the Heart Rate. In order to achieve this functionality, the paper proposes to implement Independent Component Analysis on the sources. Due to hardware constraints on a mobile device, we implement Fast-ICA (Features from Accelerated Segmentation Test) which is a form of Independent Component Analysis. Also, we limit the number of computations to ‘2.’
Figure 4: Principal Component Analysis
Thus, we pull out the most periodic signal after performing Independent Component Analysis
After pulling out the most periodic signal we performed a frequency domain analysis to calculate the period of the signal. The results were poor for elevated heart rates, and thus we couldn’t use a DFT to calculate the heart rate. Instead, we used Peak Detection technique with a “calibrated” Window Size and Stringency Level to detect the “valid” peaks of the signal. We take the average time difference between the peaks and calculate the Heart Rate.
Figure 5: Peak Detection
We faced tons of challenges while implementing this project. Some of them are listed below:
Despite facing these challenges, we achieved the goal of our project.
We dreamed of creating a Real-time heart rate tracking application and we made it into a reality! This application works like a charm but has certain limitations. Based on our experiments, we found that our application does not work well when a person breathes heavily. Also, we noticed certain bugs in the OpenCV face detection, where it detects false positives thereby affects our performance negatively. For best results, we need to reduce the camera shake while capturing the video.
We have prepared a short video demonstration (~5 min) of our project and uploaded it on YouTube.
· Monitoring the heart rate and displaying it continuously
· Performing multiple heart rate calculation when more than one person is detected
· Can be implemented for Rear-facing camera as well
· Integrating the Accelerometer module to the project to minimize the camera shake error