I am trying to create an application that can detect a heartbeat using your computerโs webcam. I have been working on the code since 2 weeks and developed this code, and here I am still
How it works? Illustrated below ...
- Face detection with opencv
- Getting a forehead image
- Apply a filter to convert it to grayscale [you can skip it]
- Search for average green pixel intensity per frame
- Saving averages to an array
- FFT application (I used a minimal library) Get heart rate from the FFT spectrum (I need help here)
Here I need help to extract the pulse from the FFT spectrum. Can someone help me. Here , it is a similar application developed in python, but I can not refuse this code, so I am developing the same in the process. Can anyone help me uncover the part of this python code where it extracts a heartbeat.
//---------import required ilbrary ----------- import gab.opencv.*; import processing.video.*; import java.awt.*; import java.util.*; import ddf.minim.analysis.*; import ddf.minim.*; //----------create objects--------------------------------- Capture video; // camera object OpenCV opencv; // opencv object Minim minim; FFT fft; //IIRFilter filt; //--------- Create ArrayList-------------------------------- ArrayList<Float> poop = new ArrayList(); float[] sample; int bufferSize = 128; int sampleRate = 512; int bandWidth = 20; int centerFreq = 80; //--------------------------------------------------- void setup() { size(640, 480); // size of the window minim = new Minim(this); fft = new FFT( bufferSize, sampleRate); video = new Capture(this, 640/2, 480/2); // initializing video object opencv = new OpenCV(this, 640/2, 480/2); // initializing opencv object opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); // loading haar cscade file for face detection video.start(); // start video } void draw() { background(0); // image(video, 0, 0 ); // show video in the background opencv.loadImage(video); Rectangle[] faces = opencv.detect(); video.loadPixels(); //------------ Finding faces in the video ----------- float gavg = 0; for (int i = 0; i < faces.length; i++) { noFill(); stroke(
source share