The Pulse app uses the back main wide camera of your iPhone and measures your heart rate pulse.
- We initialize a Video Capture object from the back camera with a frame of 300x300 and 30fps.
- We extract the
CMSampleBuffer
from every frame with the protocol ofAVCaptureVideoDataOutputSampleBufferDelegate
. - From this frame, we get the RGB (Red Green Blue) mean values of every pixel.
- We convert the RGB values to HSV (Hue Saturation Value), in order to make the model work.
- We isolate the Hue component and process it with a simple Band-pass filter.
The filter just removes any DC component and any high frequency noise from the value. - We create a simple
Timer()
withTimeInterval
at one (1) second and get the average value of the pulse's periods. - Then, if we devide that average value by 60, we have our heart rate pulse.
60 because the heart rate pulse is measured in bpms (Beats of the heart per minute).
When extracting the HSV values we increment a validFrameCounter
for identifying if the index finger is placed correctly in the back camera.
If it is above 60 then we process the Hue value with the filter.
The pulse detector gives us a threshold for pulse to -60 in order to know when to display an error message or the actual bpm value.
- iOS 12.0+
- Xcode 10.0+
- Download the project and build it with your development team.
- Congratulations 🎉!
Special thanks to Gurpreet Singh from Pubnub(read that carefully 😅) for creating the Filter and PulseDetector in Obj-C.