Giter Club home page Giter Club logo

webcam-pulse-detector's Introduction

Alt text

webcam-pulse-detector

- UPDATE: Now with Python 3.5+ and OpenCV 3.0+ support

Stand-alone (no dependancy) precompiled application:

  • Download for Windows 7 and 8: webcam-pulse-detector_win.zip (42 Mb)
  • Download for Mac OSX 10.6 (and later): webcam-pulse-detector_mac.zip (21 Mb)
  • Debian/Ubuntu/Mint Linux: Coming very soon. For now, it is recommended that you run from source on the no_openmdao branch if you just want to test things out.

The application can be run by simply executing the binary contained in the zip file for your platform. This code can also be run from source by following the instructions below.


A python code that detects the heart-rate of an individual using a common webcam or network IP camera. Tested on OSX, Ubuntu, and Windows.

How it works:

This application uses OpenCV to find the location of the user's face, then isolate the forehead region. Data is collected from this location over time to estimate the user's heart rate. This is done by measuring average optical intensity in the forehead location, in the subimage's green channel alone (a better color mixing ratio may exist, but the blue channel tends to be very noisy). Physiological data can be estimated this way thanks to the optical absorption characteristics of (oxy-) haemoglobin (see http://www.opticsinfobase.org/oe/abstract.cfm?uri=oe-16-26-21434).

With good lighting and minimal noise due to motion, a stable heartbeat should be isolated in about 15 seconds. Other physiological waveforms (such as Mayer waves) should also be visible in the raw data stream.

Once the user's heart rate has been estimated, real-time phase variation associated with this frequency is also computed. This allows for the heartbeat to be exaggerated in the post-process frame rendering, causing the highlighted forehead location to pulse in sync with the user's own heartbeat.

Support for detection on multiple simultaneous individuals in a single camera's image stream is definitely possible, but at the moment only the information from one face is extracted for analysis.

The overall dataflow/execution order for the real-time signal processing looks like:

Alt text

Requirements:

Quickstart:

  • run get_pulse.py to start the application
python get_pulse.py
  • To run on an IP camera, set the url, user, and password strings on line 134 of get_pulse_ipcam.py, then run:
python get_pulse_ipcam.py

This was tested on a Wowwee Rovio.

  • If there is an error, try running test_webcam.py in the same directory to check if your openCV installation and webcam can be made to work with this application.

Usage notes:

  • When run, a window will open showing a stream from your computer's webcam
  • When a forehead location has been isolated, the user should press "S" on their keyboard to lock this location, and remain as still as possible (the camera stream window must have focus for the click to register). This freezes the acquisition location in place. This lock can be released by pressing "S" again.
  • To view a stream of the measured data as it is gathered, press "D". To hide this display, press "D" again.
  • The data display shows three data traces, from top to bottom:
    1. raw optical intensity
    2. extracted heartbeat signal
    3. Power spectral density, with local maxima indicating the heartrate (in beats per minute).
  • With consistent lighting and minimal head motion, a stable heartbeat should be isolated in about 15 to 20 seconds. A count-down is shown in the image frame.
  • If a large spike in optical intensity is measured in the data (due to motion noise, sudden change in lighting, etc) the data collection process is reset and started over. The sensitivity of this feature can be tweaked by changing data_spike_limit on line 31 of get_pulse.py. Other mutable parameters of the analysis can be changed here as well.

webcam-pulse-detector's People

Contributors

fanquake avatar roughana avatar thearn 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  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

webcam-pulse-detector's Issues

SyntaxError: Missing parentheses in call to 'print'

System
Python 3.5.2 |Anaconda 4.1.1 (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin

Running
python get_pulse.py

Returns
File "get_pulse.py", line 100
print "Writing csv"

SyntaxError: Missing parentheses in call to 'print'

Python build crashes when locking to face

Same issue as previous but different debug, this time I'm not running the exe I built from python

face detection lock = True
Traceback (most recent call last):
  File "get_pulse.py", line 213, in <module>
    App.main_loop()
  File "get_pulse.py", line 181, in main_loop
    self.processor.run(self.selected_cam)
  File "C:\Users\WorldMachine\Downloads\webcam-pulse-detector-no_openmdao\lib\processors_noopenmdao.py", line 207, in run
    idx2 = np.argmax(pruned)
  File "C:\Users\WorldMachine\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\fromnumeric.py", line 1037, in argmax
    return _wrapfunc(a, 'argmax', axis=axis, out=out)
  File "C:\Users\WorldMachine\AppData\Local\Programs\Python\Python37\lib\site-packages\numpy\core\fromnumeric.py", line 51, in _wrapfunc
    return getattr(obj, method)(*args, **kwds)
ValueError: attempt to get argmax of an empty sequence

Unrecognized or unsupported array type in function cvGetMat

Hi,

64-bit Arch Linux
OpenCV 2.4.5
Python 2.7.4

When running python2 test_webcam.py, this happens:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /build/src/opencv-2.4.5/modules/core/src/array.cpp, line 2482
Traceback (most recent call last):
File "test_webcam.py", line 23, in
cv2.imshow("Camera", img)
cv2.error: /build/src/opencv-2.4.5/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat

Best regards,
Alexander Rødseth

TypeError: integer argument expected, got float

Hello sir,
I got this error when i lock the forehead region
please help me......

face detection lock = True
Traceback (most recent call last):
File "C:/Users/thearn-webcam-pulse-detector-3060060/thearn-webcam-pulse-detector-3060060/get_pulse.py", line 212, in
App.main_loop()
File "C:/Users/thearn-webcam-pulse-detector-3060060/thearn-webcam-pulse-detector-3060060/get_pulse.py", line 180, in main_loop
self.processor.run(self.selected_cam)
File "C:\Users\thearn-webcam-pulse-detector-3060060\thearn-webcam-pulse-detector-3060060\lib\processors_noopenmdao.py", line 238, in run
cv2.putText(self.frame_out, text,(x - w / 2, y), cv2.FONT_HERSHEY_PLAIN, tsize, col)
TypeError: integer argument expected, got float

Taking all color channels instead of green only.

For all interested - here's the original article: https://dspace.mit.edu/openaccess-disseminate/1721.1/66243
This implementation does not:

  1. use JADE algorithm to recover original independent signals, from which we take second and do the processing via Fourier transform;
  2. use not all face for processing, but only a small part of a forehead (which is probably fine although);
  3. use raw green channel for processing as particularly green channel is the closest one to represent human pulse.

Correct me if I'm wrong.

Got troubles when installing OpenMDAO and the OpenMDAO.lib.datatypes.api

When I have got OpenMDAO 0.5.5 installed, I can activate it,but got troubles in the test,and when I run the get_pulse.py,there is "No module named OpenMDAO.lib.datatypes.api."

I think there must be something wrong in the OpenMDAO,but I have no idea how to fix it.

Is there anyone who has ran this project? I need your help,thank you!

OpenMDAO does not support uninitialized variables ?

Can't get master branch running on Ubuntu 14.04

(openmdao-0.12.0)aahu@barahv2:~/Downloads/webcam-pulse-detector$ python2.7 get_pulse.py 
Traceback (most recent call last):
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1495, in _setup
    self.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1213, in setup_sizes
    self._system.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 927, in setup_sizes
    super(SimpleSystem, self).setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 933, in setup_sizes
    self.scope.raise_exception(msg, ValueError)
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/container.py", line 1353, in raise_exception
    raise exception_class(full_msg)
ValueError: : RGBsplitter.G was not initialized. OpenMDAO does not support uninitialized variables.
Traceback (most recent call last):
  File "get_pulse.py", line 151, in <module>
    App.main_loop()
  File "get_pulse.py", line 134, in main_loop
    self.processor.run()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/component.py", line 509, in run
    self._pre_execute()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 200, in _pre_execute
    self._setup()  # only call _setup from top level
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1495, in _setup
    self.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1213, in setup_sizes
    self._system.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 927, in setup_sizes
    super(SimpleSystem, self).setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 933, in setup_sizes
    self.scope.raise_exception(msg, ValueError)
  File "/home/aahu/Downloads/openmdao-0.12.0/local/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/container.py", line 1353, in raise_exception
    raise exception_class(full_msg)
ValueError: : RGBsplitter.G was not initialized. OpenMDAO does not support uninitialized variables.

IndexError: tuple index out of range

Getting an error as soon as I hit "d"

Traceback (most recent call last):
  File "/Users/chrisnicola/src/webcam-pulse-detector/get_pulse.py", line 128, in <module>
    App.main_loop()
  File "/Users/chrisnicola/src/webcam-pulse-detector/get_pulse.py", line 123, in main_loop
    self.key_handler()
  File "/Users/chrisnicola/src/webcam-pulse-detector/get_pulse.py", line 95, in key_handler
    self.key_controls[key]()
  File "/Users/chrisnicola/src/webcam-pulse-detector/get_pulse.py", line 65, in toggle_display_plot
    self.make_bpm_plot()
  File "/Users/chrisnicola/src/webcam-pulse-detector/get_pulse.py", line 81, in make_bpm_plot
    bg = self.processor.grab_faces.slices[0])
  File "/Users/chrisnicola/src/webcam-pulse-detector/lib/interface.py", line 69, in plotXY
    wd = int(bg.shape[1]/bg.shape[0]*h )
IndexError: tuple index out of range

cv2 module not found

Did anyone else have this issue? I have latest OpenCv, OpenMDAO, and python 2.7. I also did the . bin/activate.

Error on get_pulse.py exec

Ubuntu 12.10 x64. Whan does it mean?

Traceback (most recent call last):
  File "get_pulse.py", line 125, in <module>
    App = getPulseApp()
  File "get_pulse.py", line 17, in __init__
    self.camera = Camera(camera=0) #first camera by default
  File "~/Downloads/webcam-pulse-detector-master/lib/device.py", line 10, in __init__
    self.shape = self.get_frame().shape
AttributeError: 'NoneType' object has no attribute 'shape'

argmax?

Trying to use under windows 7. INstalls OK but freezes after i lock the forehead:

ValueError: attempt to get argmax of an empty sequence....

thoughts?

Please specify license

Hello,
I was hoping to expand this to cover heart rate variability and a few other features, such as continued tracking. Any chance you could specify a license? Thanks!

Frank

Feature Request: zero-pad the fft

I'm no expert in signal processing, but so far as I've been able to tell through reading online, it seems that zero-padding the fft seems to improve speed (if you zero-pad so that the signal length is a power of 2) and possibly accuracy.

Slow performance with high-res cameras

You might consider resampling the image to a lower resolution for the face detection parts; those really eat up time when dealing with large images. Once you find the face, you can use the original image to compute the stats.

comment your code please

The pipeline makes sense on a high level, but its super hard to follow the movement of the data due to zero comments and cryptic variable names. Good documentation helps other folks solve issues and build on top of what you built, plus its good juju

HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP

Ubuntu 12.04.2 OpenCV 2.4.5 Python 2.7.3

After running "python webcam-pulse-detector/get_pulse.py" I get an error
"HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP"

My webcam is turned on and I see window with webcam output when I run script.

It is not accurate

If I move my face outside the screen, it is still showing bpm values from nowhere

Feature Request: ICA on RGB

I see that your code runs an FFT on the green channel only, possibly missing out on data from the other channels. I've seen other implementations pass the RGB channel data through ICA then passing the resulting independent components through FFT. (Actually, they chose a single component to pass through the FFT, but it seems uncertain whether the same component number would contain the pulse signal every time. It therefore seems more robust to pass all channels through FFT and check them all for power in the expected range of human pulse rates.)

VIDIOC_QUERYMENU: Invalid argument

github/webcam-pulse-detector/openmdao-0.6.0$ python ../get_pulse.py
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument

Window opens with webcam image. Looks fine. But nothing happens. How long should this take?

github/webcam-pulse-detector/openmdao-0.6.0$ python ../test_webcam.py
same results

screenshot:
http://i.imgur.com/Ix8fDP4.jpg

Notice the white lines on the left of the image. Otherwise nothing different.

New user of Python need help

Hello, I am a new user of Python and I'm trying to learn by analysing this webcam-pulse-detector application but can't understand some blocks of code. Please, is there any possibility to comment each block or line in each file and eplain what it does so that you can help me understand how it works?

Thank you

Inaccurate data for many athletes with low resting heart rate

"The data is filtered between 0.8 - 3.0 Hz (48 - 180 BPM)"

Can the lowerbound of the date filter range be lowered to ~40 BPM, or is there a way to manually adjust the range, since many athletes are can fall in this range.

Would be nice to have an adjustable range, say you know your heart rate is ~45bpm, you can specify the filter range to be from 40 to 50

OS X: matplotlib and PyQT5 dependencies needed

Hi, thanks for creating this. If you could update the README to include two more dependencies: Matplotlib (for pylab) and PyQT5.

Also I had to add the following to lib/processors_noopenmdao.py before import pylab statement:

import matplotlib
matplotlib.use('QT5Agg')
import pylab

Can't get precompiled working

Thought I'd give the pre-compiled version a go. Did as it said, downloaded and executed on Macbook, Mac OS X (10.7.5). It instantly crashed. Part of the error report (below). Query then, has anyone else had issues? Is there anything else I should have before running it?

Process: get_pulse [747]
Path: /Users/USER/Downloads/*/get_pulse.app/Contents/MacOS/get_pulse
Identifier: get_pulse
Version: 0.0.0 (???)
Code Type: X86-64 (Native)
Parent Process: get_pulse [746]

Date/Time: 2014-04-22 14:20:11.464 +0100
OS Version: Mac OS X 10.7.5 (11G63)
Report Version: 9

Interval Since Last Report: 100856 sec
Crashes Since Last Report: 7
Per-App Interval Since Last Report: 10 sec
Per-App Crashes Since Last Report: 7
Anonymous UUID: 2759F8BF-8831-4BC3-9E3B-F4806FE6F56B

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000

Application Specific Information:
objc[747]: garbage collection is OFF

The image is flipped & frame rate

Hi all,

To begin with, thanks for sharing this code.
I have a quick question about flipped image whenever I ran this code.

Is there any particular reason for a flipped image on pop up window?
otherwise is it just for me?

In order to fix this problem, I add just one line on the "def get_frame of device.py" as below.


class Camera(object):

def __init__(self, camera = 0):
    self.cam = cv2.VideoCapture(camera)
    self.valid = False
    try:
        resp = self.cam.read()
        #self.shape = resp[1].shape
        self.shape = cv2.flip(resp[1].shape, 1)
        self.valid = True
    except:
        self.shape = None

def get_frame(self):
    if self.valid:
        _,frame = self.cam.read()
        frame = cv2.flip(frame, 1)
    else:
        frame = np.ones((480,640,3), dtype=np.uint8)
        col = (0,256,256)
        cv2.putText(frame, "(Error: Camera not accessible)",
                   (65,220), cv2.FONT_HERSHEY_PLAIN, 2, col)
    return frame

The reason I ask you is I would like to extract time series heart rate as a single csv file without sampling distortion.
Extracting time series signal can be utilized to analyze my personal research.

Please let me know if you guys have ideas and comments.

Thanks.

binaries for windows

great code and ideas
only may you share how you got binaries for windows
as you wrote
simply executing the binary contained in the zip file for your platform

Go to the doctor

Throbbing veins on the face - a sign of neurosis, stress disorder,
hanging blood pressure, early vegetative-vascular dystonia or migraine.
To the doctor is necessary!

face recognition implementation is racist

I am testing the no-openmdao branch and whenever my non-Caucasian friends want to try it out, the face recognition fails to detect them. It works great for me though (I am a whitey).

Issues running get_pulse.py on osx (10.10)

Hi,

This looks great, but I've been having some issues running the code.
I've activated openmdao in the downloads folder then tried to run the get_pulse.py script but I run into these errors:

Traceback (most recent call last):
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1495, in _setup
    self.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1213, in setup_sizes
    self._system.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 927, in setup_sizes
    super(SimpleSystem, self).setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 933, in setup_sizes
    self.scope.raise_exception(msg, ValueError)
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/container.py", line 1353, in raise_exception
    raise exception_class(full_msg)
ValueError: : RGBsplitter.G was not initialized. OpenMDAO does not support uninitialized variables.
Traceback (most recent call last):
  File "../../webcam-pulse-detector/get_pulse.py", line 151, in <module>
    App.main_loop()
  File "../../webcam-pulse-detector/get_pulse.py", line 134, in main_loop
    self.processor.run()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/component.py", line 509, in run
    self._pre_execute()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 200, in _pre_execute
    self._setup()  # only call _setup from top level
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1495, in _setup
    self.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/assembly.py", line 1213, in setup_sizes
    self._system.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 927, in setup_sizes
    super(SimpleSystem, self).setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 453, in setup_sizes
    sub.setup_sizes()
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/systems.py", line 933, in setup_sizes
    self.scope.raise_exception(msg, ValueError)
  File "/Users/georgeprofenza/Downloads/openmdao-0.12.0/lib/python2.7/site-packages/openmdao.main-0.12.0-py2.7.egg/openmdao/main/container.py", line 1353, in raise_exception
    raise exception_class(full_msg)
ValueError: : RGBsplitter.G was not initialized. OpenMDAO does not support uninitialized variables.

Any ideas on how initialise these variables and get script running ?

Thanks,
George

error: (-215) p.checkVector(2, CV_32S) >= 0 in function polylines

Your project looks awesome and I'm dying to try it, but unfortunately it crashes for me when I press D to show the gathered data.

I get this stack trace:

OpenCV Error: Assertion failed (p.checkVector(2, CV_32S) >= 0) in polylines, file  build/buildd/opencv-2.3.1/modules/core/src/drawing.cpp, line 2064
Traceback (most recent call last):
  File "get_pulse.py", line 127, in <module>
    App.main_loop()
  File "get_pulse.py", line 122, in main_loop
    self.key_handler()
  File "get_pulse.py", line 94, in key_handler
    self.key_controls[key]()
  File "get_pulse.py", line 64, in toggle_display_plot
    self.make_bpm_plot()
  File "get_pulse.py", line 80, in make_bpm_plot
    bg = self.processor.grab_faces.slices[0])
  File "/home/mononofu/tmp/webcam-pulse-detector/lib/interface.py", line 113, in plotXY
    cv2.polylines(z, P, False, (255,255,255),1)
cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/drawing.cpp:2064: error: (-215) p.checkVector(2, CV_32S) >= 0 in function polylines

The parameter P passed to polylines looks like this when the crash happens: (I assume z, the image, can't have any effect)

[array([[ 10,  11],
       [ 18,  12],
       [ 23,  15],
       [ 29,  10],
       [ 35,  41],
       [ 40,  28],
       [ 46,  15],
       [ 52,  22],
       [ 57,  22],
       [ 63,  26],
       [ 68,  31],
       [ 74,  30],
       [ 80,  34],
       [ 85,  33],
       [ 91,  31],
       [ 97,  33],
       [103,  32],
       [108,  33],
       [114,  30],
       [119,  29],
       [125,  28],
       [131,  27],
       [137,  31],
       [142,  33],
       [148,  48],
       [154,  52],
       [160,  55],
       [165,  64],
       [171,  64],
       [177,  70],
       [183,  68],
       [189,  65],
       [194,  59],
       [200,  57],
       [205,  54],
       [211,  48],
       [217,  47],
       [222,  42],
       [228,  44],
       [234,  44],
       [240,  46],
       [245,  48],
       [251,  49],
       [257,  53],
       [263,  53],
       [268,  48],
       [274,  48],
       [280,  43],
       [286,  43],
       [291,  39],
       [297,  37],
       [303,  33],
       [308,  31],
       [314,  34],
       [320,  29],
       [325,  28],
       [331,  25],
       [336,  29],
       [342,  35],
       [347,  32],
       [353,  34],
       [358,  33],
       [364,  33],
       [370,  32],
       [375,  32],
       [381,  33],
       [386,  30],
       [392,  33],
       [397,  29],
       [403,  32],
       [409,  32],
       [415,  28],
       [420,  30],
       [426,  27],
       [432,  29],
       [437,  27],
       [443,  24],
       [448,  24],
       [454,  23],
       [460,  24],
       [465,  20],
       [471,  21],
       [476,  29],
       [482,  31],
       [488,  32],
       [494,  30],
       [499,  32],
       [505,  29],
       [510,  32],
       [516,  35],
       [521,  32],
       [527,  31],
       [533,  32],
       [538,  29],
       [544,  35],
       [550,  37],
       [555,  38],
       [561,  48],
       [567,  48],
       [573,  52],
       [578,  49],
       [584,  50],
       [590,  49],
       [595,  51],
       [601,  55],
       [607,  58],
       [612,  62],
       [618,  60],
       [624,  63],
       [630,  60]]), array([[ 10, 105],
       [ 16, 127],
       [ 22, 142],
       [ 28, 149],
       [ 34, 150],
       [ 40, 146],
       [ 46, 141],
       [ 52, 137],
       [ 59, 136],
       [ 65, 135],
       [ 71, 134],
       [ 77, 131],
       [ 83, 125],
       [ 89, 117],
       [ 95, 107],
       [102,  98],
       [108,  92],
       [114,  90],
       [120,  91],
       [126,  98],
       [132, 106],
       [138, 117],
       [145, 127],
       [151, 135],
       [157, 141],
       [163, 143],
       [169, 142],
       [175, 138],
       [181, 132],
       [188, 124],
       [194, 115],
       [200, 107],
       [206, 101],
       [212,  98],
       [218,  99],
       [224, 102],
       [230, 107],
       [237, 114],
       [243, 120],
       [249, 126],
       [255, 129],
       [261, 130],
       [267, 130],
       [273, 128],
       [280, 126],
       [286, 123],
       [292, 120],
       [298, 118],
       [304, 115],
       [310, 113],
       [316, 112],
       [323, 111],
       [329, 111],
       [335, 113],
       [341, 115],
       [347, 118],
       [353, 120],
       [359, 122],
       [366, 122],
       [372, 122],
       [378, 121],
       [384, 120],
       [390, 119],
       [396, 119],
       [402, 119],
       [409, 119],
       [415, 120],
       [421, 120],
       [427, 120],
       [433, 119],
       [439, 118],
       [445, 117],
       [451, 115],
       [458, 114],
       [464, 113],
       [470, 113],
       [476, 114],
       [482, 116],
       [488, 119],
       [494, 122],
       [501, 125],
       [507, 127],
       [513, 128],
       [519, 126],
       [525, 122],
       [531, 117],
       [537, 112],
       [544, 107],
       [550, 106],
       [556, 106],
       [562, 110],
       [568, 114],
       [574, 119],
       [580, 123],
       [587, 126],
       [593, 128],
       [599, 131],
       [605, 134],
       [611, 139],
       [617, 144],
       [623, 146],
       [630, 143]]), array([[ 10, 208],
       [ 87, 170],
       [164, 197],
       [242, 200],
       [319, 225],
       [397, 219],
       [475, 229],
       [552, 226],
       [630, 230]])]```

Unfortunately I don't know enough about OpenCV to figure out the problem.

Ask for help

hi,
Thank you for sharing your code.I would like to ask if you have any good ways to deal with slight head movements to measure pulse.
Look forward to your reply.Thank you!

Suggested code change for more robust head detection.

Try replacing the two lines at ~84 in detectors.py

if self.return_one:            
    self.detected[0] = detected[0]

with

if self.return_one:            
    width = detected[0][2]
    height = detected[0][3]
    for i in range(1,len(detected)):
        if detected[i][2] > width and detected[i][3] > height: 
            detected[0] = detected[i]
            width = detected[i][2]
            height = detected[i][3]
    self.detected[0] = detected[0]

This provides much more robust head tracking by always returning the single largest head in the image rather than the first head returned in the detector array. Makes the head detection more stable and may allow you to not have to use the 'S' key.

Thanks for releasing this.

Mike

Cannot start get_pulse.py

This is the error I'm getting:

(openmdao-0.6.2) C:...\webcam-pulse-
detector-master>python get_pulse.py
Traceback (most recent call last):
File "get_pulse.py", line 2, in
from lib.processors import findFaceGetPulse
File "C:...\webcam-pulse-detector-master\lib\processors.py", line 2, in
from openmdao.main.api import Component, Assembly
File "C:...\openmdao-0.6.2\lib\site-packages\openmdao.main-0.6.
2-py2.7.egg\openmdao\main\api.py", line 16, in
from openmdao.main.component import Component, SimulationRoot
File "C:...\openmdao-0.6.2\lib\site-packages\openmdao.main-0.6.
2-py2.7.egg\openmdao\main\component.py", line 38, in
from openmdao.main.publisher import Publisher
File "C:...\openmdao-0.6.2\lib\site-packages\openmdao.main-0.6.
2-py2.7.egg\openmdao\main\publisher.py", line 19, in
from pyV3D import WV_Wrapper
File "C:...\openmdao-0.6.2\lib\site-packages\pyv3d-0.4.1-py2.7-
win32.egg\pyV3D__init__.py", line 1, in
from _pyV3D import *
ImportError: DLL load failed: The specified module could not be found.

Thanks in advance!

Zero padding for interpolation of the input sample in frequency space

Maybe I missed it in the code but you should initialise the sample array to the full length and fill it with zeros. I think your code just appends to the sample so it gradually grows. Filling with zeroes creates interpolation of the signal in the frequency space making the resolution of your initial estimate higher. A longer FFT result has more frequency bins that are more closely spaced in frequency thus creating a better estimate of pulse from a small sample.

Program crashes when locking onto face

Every time I hit S I get the following debug line and the program freezes:

WARNING: file already exists but should not: C:\Users\WORLDM~1\AppData\Local\Temp\_MEI57802\Include\pyconfig.h
init done
opengl support available
face detection lock = True
Traceback (most recent call last):
  File "<string>", line 212, in <module>
  File "<string>", line 180, in main_loop
  File "D:\webcam-pulse-detector\build\get_pulse_win\out00-PYZ.pyz\lib.processors_noopenmdao", line 208, in run
  File "D:\webcam-pulse-detector\build\get_pulse_win\out00-PYZ.pyz\numpy.core.fromnumeric", line 738, in argmax
ValueError: attempt to get argmax of an empty sequence

I have successfully run it

hey ,i have to say that your work is amazing and thank you!

However, i get some trouble with running your code, at beginning---including setting env,figure out the question why my mac just turns cam led on but gets nothing else.

after some hours work, actually, i got it works.
later, i will post my change. maybe my change only fits mine ,however, i hope i can help somebody get useful info.

No licence specified

Hi,

Could you please mention under which licence this (cool) code is published?

Thanks,

Plotting error: assertion failed

When enabling plotting, the following error is happening:

bpm plot enabled

OpenCV Error: Assertion failed (mat.isContinuous()) in unknown function, file ..
\..\..\opencv-2.4.4\modules\core\src\opengl_interop.cpp, line 1153
Traceback (most recent call last):
  File "get_pulse.py", line 127, in <module>
App.main_loop()
  File "get_pulse.py", line 122, in main_loop
self.key_handler()
  File "get_pulse.py", line 94, in key_handler
self.key_controls[key]()
  File "get_pulse.py", line 64, in toggle_display_plot
self.make_bpm_plot()
  File "get_pulse.py", line 80, in make_bpm_plot
bg = self.processor.grab_faces.slices[0])
  File "e:\docs\test\webcam-pulse-detector-master\lib\interface.py", line 113, i
n plotXY
cv2.imshow(name,z)
cv2.error: ..\..\..\opencv-2.4.4\modules\core\src\opengl_interop.cpp:1153: error
: (-215) mat.isContinuous()

I have Windows, Python 2.7, OpenCV 2.4.4 and OpenMDAO 0.5.5 and the 'S' part works perfectly.

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.