Once I came across a description of an Android application that measured the heart rate remotely by using the smartphone’s camera. The camera was not touching to the skin, also was not illuminated by LED. An interesting point was that the Google Play reviewers did not believe in the possibility of such a measurement, and the application was rejected. I don’t know the end of this story, but it became interesting to check whether this is possible. There is no need to make an Android application, it is much easier to test the idea in Python.Let’s get started.

Getting the Camera Stream

First, we need to get a stream from the webcam, for which I will use OpenCV. The code is cross-platform and can run on both Windows and Linux/OSX.

import cv2
import io
import time

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
cap.set(cv2.CAP_PROP_FPS, 30)
while(True):
    ret, frame = cap.read()
    img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    ## Display the frame
    cv2.imshow('Crop', crop_img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

The idea of determining the heart rate is that the skin tone changes slightly due to the blood flow in the vessels. So we need a picture crop, which contains only a fragment of the skin:

#python #signal-processing #programming #algorithms

Remote Heart Rate Detection using Webcam and 50 Lines of Code
2.75 GEEK