Git Product home page Git Product logo

atheartrate's Introduction

ATHeartRate

This project provides a way for iOS devices to detect a user's heart rate using their device's camera. It requires iOS 8 to be running on the device. Usage is quite simple, as only a single class file is needed. An example is as follows:

self.heartRateDetectionModel = [HeartRateDetectionModel alloc] init];
self.heartRateDetectionModel.delegate = self;
[self.heartRateDetectionModel startDetection];

Make sure to add the AVFoundation.framework reference to your project.

The user's heart rate is taken over the course of 30 seconds. A user's current calculated heart rate is sent back to the delegate every 2 seconds on the main thread so the UI can update if desired. Heart rate is currently being processed by the camera at 30 fps, but work is being done to add 60, 120, and 240 fps detection assuming a user's device supports these framerates.

This project was originally developed for use in the iOS app Fit Weightlifting

atheartrate's People

Contributors

lehn0058 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

atheartrate's Issues

How to return heartrate?

So I implemented all the functions required below like this:

-(void)heartRateStart
{
NSLog(@"started!");
}

  • (void)heartRateUpdate:(int)bpm atTime:(int)seconds;
    {
    NSLog(@"Value is %i", bpm);
    }
    -(void)heartRateEnd
    {
    NSLog(@"started!");
    }

Which function actually returns my heartrate? I come from a swift background so objective-c is shaky for me.

Question from newbie

Hi,

Thanks you for this great class.
But I'm a newbie and tried to use your lib today and result: camera flash start and stop directly on iphone 5c IOS 9.
Not sure what I did wrong.
My viewController.h:

import <UIKit/UIKit.h>

import "HeartRateDetectionModel.h"

@interface ViewController : UIViewController

  • (IBAction)Start:(id)sender;
    @Property (weak, nonatomic) IBOutlet UILabel *label;
    @EnD

and my viewController.m

import "ViewController.h"

import "HeartRateDetectionModel.h"

@interface ViewController ()
@EnD
@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    }
  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }
  • (IBAction)Start:(id)sender {
    HeartRateDetectionModel *hr = [[HeartRateDetectionModel alloc]init];
    hr.delegate = self;
    [hr startDetection];
    }
    -(void)heartRateStart {
    NSLog(@"started!");
    self.label.text = @"started!";
    }
    -(void)heartRateEnd {
    NSLog(@"Stopped!");
    self.label.text = @"started!";
    }
    -(void)heartRateUpdate:(int)bpm atTime:(int)seconds {
    NSLog(@"running!");
    self.label.text = @"running!";
    }@EnD

Like I said, still I newbie, any idea why flash just start and stop?

Thank you in advance for your help.

Dams

Heart rate integration fails

Hi,

I am new to this thing,
I get your library and checked the code.
It is written awesome.

I am facing issue to integrate into my code.
I am using Xcode 7.3 and checking on iOS 9.3

Here is my code...

in ViewController.h file

import <UIKit/UIKit.h>

import "HeartRateDetectionModel.h"

@interface ViewController : UIViewController
@Property (nonatomic, strong) HeartRateDetectionModel *hr;
@EnD

in ViewController.m file

import "ViewController.h"

import "HeartRateDetectionModel.h"

@interface ViewController ()

@EnD

@implementation ViewController

@synthesize hr;

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.hr = [[HeartRateDetectionModel alloc] init];
    self.hr.delegate = self;
    [self.hr startDetection];
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

-(void)heartRateStart
{
NSLog(@"started!");
}

when I didn't wrote the method "heartRateStart" it was crashing saying "unrecognized selector sent to instance"

now if I do so,
It says
"-[ViewController heartRateUpdate:atTime:]: unrecognized selector sent to instance"

am I following correct guidelines for implementation.
Every time when I integrate your files in any app, do I need to declare all these delegates methods and call to them externally....?

Heart Rate keeps incrementing

Hi, I was using your code gist to calculate the heart rate from iPhone camera but it seems I am missing some essential part here.

I am setting frame rate at 30fps and making all calculations as per the frame rate, however, the heart rate value keeps on increasing with each call. Initially, my app was crashing because the percentage value comes <1 and we cannot divide by zero let heartRate = peakCount / percentage

I added a check for percentage, and execute the above code only if percentage >0. But it seems it affects the overall result.

Trying to achieve this in Swift 5, here is my code snippet:

if (self.hueDataSet.count % framePerSeconds == 0) {
                let displaySeconds = hueDataSet.count / framePerSeconds
                let bandpassFilteredItems = self.butterworthBandpassFilter(inputData: self.hueDataSet)
                let smoothedBandpassItems = self.medianSmoothing(inputData: bandpassFilteredItems)
                let peakCount = self.peakCount(inputData: smoothedBandpassItems)
                
                let secondsPassed = smoothedBandpassItems.count / framePerSeconds
                let percentage = secondsPassed / 60
                
                if percentage > 0 {
                    let heartRate = peakCount / percentage
                    print("heart rate: ", heartRate, "in seconds: ", displaySeconds)
                }
            }

Also, attaching log here:

heart rate: 139 in seconds: 60
heart rate: 142 in seconds: 61
heart rate: 145 in seconds: 62
heart rate: 147 in seconds: 63
heart rate: 149 in seconds: 64
heart rate: 151 in seconds: 65
heart rate: 153 in seconds: 66
heart rate: 155 in seconds: 67
heart rate: 158 in seconds: 68
heart rate: 160 in seconds: 69
heart rate: 161 in seconds: 70
heart rate: 163 in seconds: 71
heart rate: 165 in seconds: 72
heart rate: 167 in seconds: 73
heart rate: 169 in seconds: 74
heart rate: 171 in seconds: 75
heart rate: 173 in seconds: 76
heart rate: 175 in seconds: 77
heart rate: 178 in seconds: 78
heart rate: 179 in seconds: 79
heart rate: 182 in seconds: 80
heart rate: 185 in seconds: 81
heart rate: 187 in seconds: 82
heart rate: 189 in seconds: 83
heart rate: 193 in seconds: 84
heart rate: 196 in seconds: 85
heart rate: 198 in seconds: 86

I am not sure which place to debug the code. Any help is would be helpful thanks ๐Ÿ‘๐Ÿผ

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.