Skip to content

Commit

Permalink
fixed tabs vs spaces issue
Browse files Browse the repository at this point in the history
Signed-off-by: Tristan Hearn <[email protected]>
  • Loading branch information
thearn committed Jul 18, 2013
1 parent f2f8799 commit 163bd9a
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions get_pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class getPulseApp(object):
"""
Python application that finds a face in a webcam stream, then isolates the
forehead.
Then the average green-light intensity in the forehead region is gathered
over time, and the detected person's pulse is estimated.
"""
Expand All @@ -19,37 +19,37 @@ def __init__(self):
self.pressed = 0
#Containerized analysis of recieved image frames (an openMDAO assembly)
#is defined next.

#This assembly is designed to handle all image & signal analysis,
#such as face detection, forehead isolation, time series collection,
#heart-beat detection, etc.

#Basically, everything that isn't communication
#to the camera device or part of the GUI
self.processor = findFaceGetPulse(bpm_limits = [50,160],
data_spike_limit = 25.,
face_detector_smoothness = 10.)

#Init parameters for the cardiac data plot
self.bpm_plot = False
self.plot_title = "Cardiac info - raw signal, filtered signal, and PSD"

#Maps keystrokes to specified methods
#(A GUI window must have focus for these to work)
self.key_controls = {"s" : self.toggle_search,
"d" : self.toggle_display_plot}
"d" : self.toggle_display_plot}


def toggle_search(self):
"""
Toggles a motion lock on the processor's face detection component.
Locking the forehead location in place significantly improves
data quality, once a forehead has been sucessfully isolated.
"""
state = self.processor.find_faces.toggle()
print "face detection lock =",not state

def toggle_display_plot(self):
"""
Toggles the data display.
Expand All @@ -63,15 +63,15 @@ def toggle_display_plot(self):
self.bpm_plot = True
self.make_bpm_plot()
moveWindow(self.plot_title, self.w,0)

def make_bpm_plot(self):
"""
Creates and/or updates the data display
"""
plotXY([[self.processor.fft.times,
self.processor.fft.samples],
[self.processor.fft.even_times[4:-4],
self.processor.measure_heart.filtered[4:-4]],
[self.processor.fft.even_times[4:-4],
self.processor.measure_heart.filtered[4:-4]],
[self.processor.measure_heart.freqs,
self.processor.measure_heart.fft]],
labels = [False, False, True],
Expand All @@ -81,23 +81,23 @@ def make_bpm_plot(self):
skip = [3,3,4],
name = self.plot_title,
bg = self.processor.grab_faces.slices[0])

def key_handler(self):
"""
Handle keystrokes, as set at the bottom of __init__()
A plotting or camera frame window must have focus for keypresses to be
detected.
"""
self.pressed = waitKey(10) & 255 #wait for keypress for 10 ms
if self.pressed == 27: #exit program on 'esc'
print "exiting..."
self.camera.cam.release()
exit()
print "exiting..."
self.camera.cam.release()
exit()
for key in self.key_controls.keys():
if chr(self.pressed) == key:
self.key_controls[key]()

def main_loop(self):
"""
Single iteration of the application's main loop.
Expand All @@ -106,27 +106,28 @@ def main_loop(self):
frame = self.camera.get_frame()
self.h,self.w,_c = frame.shape


#display unaltered frame
#imshow("Original",frame)

#set current image frame to the processor's input
self.processor.frame_in = frame
#process the image frame to perform all needed analysis
self.processor.run()
#collect the output frame for display
output_frame = self.processor.frame_out

#show the processed/annotated output frame
imshow("Processed",output_frame)

#create and/or update the raw data display if needed
if self.bpm_plot:
self.make_bpm_plot()

#handle any key presses
self.key_handler()

if __name__ == "__main__":
App = getPulseApp()
while True:
App.main_loop()
App.main_loop()

0 comments on commit 163bd9a

Please sign in to comment.