Skip to content

A p5.js library for heart rate detection using only the webcam

License

Notifications You must be signed in to change notification settings

ziyuan-linn/p5WebcamPulse.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

p5WebcamPulse.js

Description

This is a p5.js library for heart rate detection using only the webcam footage. This project uses PPG (Photoplethysmogram)to detect the slight color change of your face or finger and calculates your heart rate. This project is inspired by the work of serghov.

This project has two detection modes. In "finger" mode, you place a finger on the webcam; this mode is often more accurate. In "face" mode, the webcam automatically tracks a region of your face for detection. For both detection methods, you have to remain relatively still to get an accurate result.

Usage

p5.js Web Editor

Make a copy of this p5.js Web Editor example and get started by editing the sketch.js file.

Download

  1. Download P5WebcamPulse.js and include it in your working directory.

  2. Add the following code to the html file.

<script src="WebcamPulse.js"></script>
  1. Create a global variable and initialize the detector object with the following code in setup().
detector = new P5WebcamPulse();

Methods

  1. P5WebcamPulse.setDetectionMode(mode)

Set the detection mode to either face or finger.

detector.setDetectionMode("face");
//or
detector.setDetectionMode("finger");
  1. P5WebcamPulse.displayVideo()

Display one frame of the webcam video with the detection region marked, usually called in draw().

detector.displayVideo();
  1. P5WebcamPulse.getProcessedBrightness()

Get the relative brightness of the detection region based on past samples, return a value between -1 and 1.

detector.getProcessedBrightness();
  1. P5WebcamPulse.getRawBrightness()

Get the relative brightness of the detection region, return a value between 0 and 255.

detector.getRawBrightness();
  1. P5WebcamPulse.getHeartRate()

Get the current heart rate in beats per minute.

detector.getHeartRate();

About

A p5.js library for heart rate detection using only the webcam

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published