Extension or blocks in AI2 that allows you to calculate the heart rate

Good morning. Is there an extension or blocks in AI2 that allows you to calculate the heart rate when the user places their finger on the smartphone's camera/flash?

Short answer: no, but it could be written
Don't hesitate to do also a search in the community as @Anke suggested

Below the answer from Gemini, I asked if it generally is possible to write an Android app to do it.

Taifun

.---

That is a fantastic question! The answer is a resounding yes, it is absolutely possible to write an Android app that measures heart rate using the phone's camera and flash.

​This technique is based on a method used in medical devices called Photoplethysmography (PPG). Here is the core concept .

​How the Technology Works (PPG)

  1. ​Illumination: When you place your finger over the camera and the flash is turned on, the LED acts as a light source, shining light onto your skin.
  2. ​Absorption & Reflection: Your blood absorbs light. As your heart beats, the amount of blood in the capillaries and arterioles of your fingertip constantly changes (it swells and recedes). This change in blood volume causes a corresponding, subtle variation in the amount of light that is reflected back to the camera sensor.
  3. ​Signal Capture: The camera's sensor captures a video stream of this tiny color change. Because blood absorbs the green spectrum of light most effectively, image processing algorithms typically focus on tracking the green color channel in the video frames.
  4. ​Processing: The app extracts the time-series signal of color intensity fluctuations (the PPG signal). This signal is then filtered to remove noise (like movement) and analyzed using algorithms (often Fast Fourier Transform or peak detection) to count the number of peaks—which correspond directly to your heartbeats—to calculate the Beats Per Minute (BPM).

​ Key Takeaways for a Real Android App:

  1. ​API Usage: In a real Android app, you would use the CameraX library (recommended modern approach) or Camera2 API to access the camera stream and its preview frames.
  2. ​Flash Control: You would specifically use the setTorchMode(true) function to turn on the LED flash.
  3. ​Frame Processing: You would implement a ImageAnalysis.Analyzer to process the ImageProxy (each frame) in real-time, calculate the average green pixel intensity, and feed that data into a signal processing algorithm (like the mock mockCalculateBPM function in this demo) to accurately determine the BPM.
1 Like

Nobel Prize to whoever can generate blocks for heart rate reading. Unfortunately, I'm not very good... I'll look for an ideal API (camera2API or something else)

1 Like