Coder Social home page Coder Social logo

prouast / heartbeat Goto Github PK

View Code? Open in Web Editor NEW
530.0 22.0 147.0 81.7 MB

Desktop implementation of Remote Photoplethysmography – Measuring heart rate using facial video.

License: GNU General Public License v3.0

C++ 98.49% Makefile 1.51%
heart-rate remote-photoplethysmography rppg video heart-rate-monitor face heart-rate-measurement pulse remote-sensing video-processing

heartbeat's People

Contributors

csavur avatar pierrefritsch avatar prouast avatar vowstar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heartbeat's Issues

application was unable to start correctly (0xc000007b)

image
I somehow managed to compile the code through mingw. Now This is what i am getting after executing the exe file. I have updated .net framework and visual c++ but still cant get rid of it. Is there something missing in the project code?
Is it because the code was written for unix but i am running it on windows?

Code performance and porting to Python

Hi @prouast,

First all of all, thanks for the great work. I wanted to ask two things specifically:

  1. Is this code base still relevant with respect to the current SOTA in rPPG estimation? If not, which are the improvements that you think should be tackled with the highest priority at its current state?
  2. How robust to motion is your implementation?
  3. How challenging would it be to port it all to Python? I gave a quick glance at the repository, and was debating which path would be the easiest between re-implementing your whole logic in Python or wrapping your C++ code with Python binders.

As you may have already assumed, I would need this code to talk to a larger Python module.

Increasing performance and tweaking

First of all, thank you for the amazing research done @prouast. I was wondering whether the FPS affects the accuracy of the pulse count. I am getting ~6.5 FPS on my PC. I saw on your youtube video that you were getting constant 30FPS. Also my FPS count was variable and not locked. If there is a way to lock FPS let me know.

Confusion on rescanning

Hello. I am trying to understand the rescanning portion of your code here:

} else if ((time - lastScanTime) * timeBase >= 1/rescanFrequency) {

How is this condition satisfied and what is its purpose? I am assuming time is incremented by 1, so how is time-lastScanTime' never != 1? Also, it looks like timeBase is set to .001, so how can (time - lastScanTime) * timeBase` ever be >= 1/reScanFrequency? From my understanding, this results in .001 >= 1, which is never true. Please let me know what I am missing.

Thanks!

Environment requirements

Hi,
I can compile and run the Heartbeat demo now. But I see the bpm value is varying all the time. I think the reason cause this issue is the difference between my test environment and your develop environment. Can you provide the environment requirements for this project (like inside or outside, how much light should project on face etc.).

thank you

Measure high bpm after workout.

Hello. At first, thank you for your amazing work!
I tried to get high heartrate using your code, but I can't achieve it. When I measure heartrate at 30 fps, I could detect high bpm easily , but below 15 fps I couldn't detect high bpm.
I tried to figure out why, so I analyzed raw signal and figured out there is so much fluctuation after workout. Maybe this is the reason why I can't get high bpm at low fps.
However, I watched your youtube video about rppg, and I shocked because you can get high bpm at low fps.
So, I wonder why this happens and how can I get high bpm at low fps. Please let me know.

Thank you for your great work again!

How about only using keypoints and no masking?

In your current code:

  • you define a rectangle on the forehead.
  • Then use the 4 corners and do openCV optical flow keypoint tracking to get smoother tracking
  • use estimateAffine2D to rectify the tracked area.
  • Based on this rectangle you create a mask and analyze only the RGB image based on the mask.

What do you think how accurate the PPG analysis would be if i defined 1000 optical flow keypoints and got the mean RGB value from those 1000 pixel points?
The keypoint tracking ensures that we are reading the same skin pixels throughout consecutive frame. But i don't know if 1000 points is too low or if we need a continuous 2D space.

Thanks for your advice.

handRPPG.mov

get trigger at peak

Thank you again for posting this code.
I am able to make it run and I find it works great. I was even able to integrate it in to a openframeworks.cc application.

I was hoping you could point me to the right part of the code where I might be able to extract the moment of a peak. My goal is to make the heart beat readings audible by playing a sound every time we get a peak. The hope if that it will align more or less with the person's actual pulse.

Thank you for any advice.

error when running

Hi thanks for sharing this project. when I compile and running the heartbeat file showing the below error:

Using algorithm 0.
Face classifier xml not found!

any way to fix ?

thanks

Compile code for Windows

g++ -std=c++11 -LC:\Users\Anon\Desktop\ffmpeg-20171225-613f789-win32-shared\bin -LC:\Anaconda\pkgs\opencv3-3.1.0-py35_0\Library\lib -lopencv_core310 -lopencv_highgui310 -lopencv_imgcodecs310 -lopencv_imgproc310 -lopencv_objdetect310 -lopencv_video310 -lopencv_videoio310 -lavcodec-58 -lavformat-58 -lavutil-56 -lswscale-5 ?

OSC output

Thank you so much for sharing this create example project.
It works very well as far as I can tell.

You know what would be super nice ;), if your code would integrate OSC (open sound control) as an output option. This would make it so easy for other to grab that data and use it in their own projects. Also it would make it Independent of c++.

Just a thought.

All the best.

Error on run, Face classifier xml not found!

  • Environment
    MacOS Mojave 10.14.2

  • Compiling using:
    g++ -std=c++11 -I/usr/local/Cellar/opencv/4.0.1/include/opencv4 -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_objdetect -lopencv_video -lopencv_videoio Heartbeat.cpp opencv.cpp RPPG.cpp Baseline.cpp -o Heartbeat

  • Getting following warnings

        Mat transform = estimateRigidTransform(corners_0v, corners_1v, false);
                        ^
/usr/local/Cellar/opencv/4.0.1/include/opencv4/opencv2/video/tracking.hpp:258:1: note: 'estimateRigidTransform' has been explicitly marked deprecated here
CV_DEPRECATED CV_EXPORTS Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine );
^
/usr/local/Cellar/opencv/4.0.1/include/opencv4/opencv2/core/cvdef.h:346:43: note: expanded from macro 'CV_DEPRECATED'
#    define CV_DEPRECATED __attribute__ ((deprecated))
  • Running Heartbeat getting following error
Using rPPG algorithm 0.
Using face detection algorithm 0.
Face classifier xml not found!

[Process completed]
  • Even though 'haarcascade_frontalface_alt.xml' file is located in the same directory. Any guidance is appreciated.

use IR videos

Do you think your method would work on an camera feed with irPass filter, like discussed here:
https://arxiv.org/pdf/1902.05194.pdf ?

In your code you get the mean RGB value. So maybe using the mean IR as they mention "we compute the mean IR value on each region" could work too?

Liveness Detection

Hello, great work!

Is there a way to verify if the person is placing a photo or image instead of a real face ?

Thank you.

id returned 1 exit status

image

I cant figure out whats wrong with it? I am using windows 8 , compiler TDM-GCC mingw , opencv 3.4.1

rPPG非接触式心率测量

你好,请问你在浦源创建的“rPPG非接触式心率测量”的应用的源码是来源于这个仓库吗

ld error

Thanks your code ,but when i compile the source code , the error happend

undefined reference to symbol 'avcodec_open2@@LIBAVCODEC_FFMPEG_56'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libavcodec.so: error adding symbols: DSO missing from command line

I need help .Thankyou.

Sharing executable

Thanks for your great code. I am having trouble compiling on my Mac. If you already compiled on Mac, can you share the executable? Thanks!

FaceValid is True once the programming running?

Hi,
I have a question when I run the code. Hope that you could help me to get out.

when I debug the code with the pdb tools, I found the faceValid is true when I first get into the rppg.processFrame() function, which leads to not call the detectFace function before call the traceFace function. I don't know where makes the faceValid true at the beginning of the code. Do I understand wrong with the program ?

Thank you.

Poor performance with video files recorded using auto settings on DSLR camera

I have recorded some video footage using a Nikon D750 DSLR camera and have kept auto-focus and auto for all other settings. The room is well lit, the subjects face fills the frame and there is little movement.
The results are poor when compared to the ground-truth, which has been measured using a Polar H10 chest-strap sensor.
When checking the metadata for the videos I have noticed that the ISO varies significantly (280 - 1800) across different subjects. In particular, it's high for those with dark skin tone and performs poorly with those. The best performing subject doesn't have the lowest ISO though.

@prouast Is the ISO a significant factor in determining the quality of the results or is there anything else I should consider with the data?

Getting heart rate from one single picture

Hi

I took a video from one single picture for 20 seconds,then using it to test.however,I can also get the heart rate just like human's. Do you have any idea about this?

Regards
MLQUE

getFps function and fps variable confusion

I can't figure out what the getFps function is doing. I see it is called in in RPPG.cpp to create the fps variable, but I can't figure out what the intention is. Could you clarify and break down what the goal of this function and the fps variable is? Forgive me if this is already written in a paper/blog, but I've searched extensively and can find no information.

The function in opencv.cpp:

        double getFps(Mat &t, const double timeBase) {

        double result;

        if (t.empty()) {
            result = 1.0;
        } else if (t.rows == 1) {
            result = std::numeric_limits<double>::max();
        } else {
            double diff = (t.at<int>(t.rows-1, 0) - t.at<int>(0, 0)) * timeBase;
            result = diff == 0 ? std::numeric_limits<double>::max() : t.rows/diff;
        }

        return result;
    }

The code in RPPG.cpp:

        if (faceValid) {

        // Update fps
        fps = getFps(t, timeBase);
        cout << fps << endl;
        // Remove old values from raw signal buffer
        while (s.rows > fps * maxSignalSize) {
            push(s);
            push(t);
            push(re);
        }
        cout << "s: " << s.rows << " t: " << t.size() <<endl;

        assert(s.rows == t.rows && s.rows == re.rows);

        // New values
        Scalar means = mean(frameRGB, mask);
        // Add new values to raw signal buffer
        double values[] = {means(0), means(1), means(2)};
        s.push_back(Mat(1, 3, CV_64F, values));
        t.push_back(time);

        // Save rescan flag
        re.push_back(rescanFlag);

        // Update fps
        fps = getFps(t, timeBase);

I ask because if I change the ROI size, the s and t variables change which drastically effects (in a bad way) the signal quality/bpm prediction. Why is this?

Docs for loading baseline

I'm trying to load baseline physiological data from a csv file. I'm running into segmentation faults. It'd be great if you could include some documentation on how to use the baseline argument and the format of the baseline csv file

HEART

could you share a heart python

Heart rate changes rapidly

Hi
Actually heart rate changes rapidly for example from 80 to 50 then 70 ... .
So i think the max change should be for instance 2 BPM per second. Do you have any idea about this?

My second question is about the time in csv file. Could you please explain a little bit about it? (eg. 9394881, 9395903, 9396906)

Also could please explain a little bit about max time window ?

And finally, because i think your app is not accurate when there are a lot of movements and also the system could not detect face at a distance more than 0.5 m. Do you think using dlib will improve your app?

Regards
Javad

OpenCV Error

Hi
After compiling the source-code, and trying to run the program I got this error.
Do you have nay idea for fixing this issue?

centan@centan-Vostro-3800:~/Desktop/Heartbeat$ ./Heartbeat
Using algorithm 0.
SIZE: 640x480
FPS: 30
MSEC: 0
Tracking face
OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in calcOpticalFlowPyrLK, file /home/centan/Downloads/opencv-3.1.0/modules/video/src/lkpyramid.cpp, line 1114
terminate called after throwing an instance of 'cv::Exception'
what(): /home/centan/Downloads/opencv-3.1.0/modules/video/src/lkpyramid.cpp:1114: error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK

update Repo

could you update the repo to include pos ,fav and chrome algorithms

Is there a respiratory rate implementation

Hi, iam working on rppg for about 4 months and I take this project as a source to study from I changed some stuff like using ncnn implantation and more my question is there is respiratory rate implantation to use in cpp

edit: i read a lot on hypered can and mtts can but this need lots of efforts to be generated for android device any advice?

Found no face

I test on video with -i arguments, but the log prints Found no face, why is that?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.