I’ve been experimenting with methods to determine my heart rate in order to add bio-feedback to software. This Processing sketch uses the same principle as the devices in the doctor’s office that clip on to your finger. When your heart beats, more blood is pumped through the capillaries in your fingertip, thus absorbing more light and causing a slight darkening of your fingertip.
To use the code you’ll need a copy of Processing. Shine a bright flashlight against your thumbnail (I used a bright LED flashlight) and place your thumb over the webcam lens so it completely blocks it. Try to hold as still as possible. The brightness of the red channel is measured each frame and a running average is kept. If the brightness drops below the recent average, a small circle is drawn representing a contracting heart.
If it is unreliable, you may need to tweak the navg parameter and/or find a way to stabilize the light source, finger, and camera, as small shifts will cause a change in the amount of light detected by the camera.