Skip to content

Commit

Permalink
added tests and .gitignore file, performed spell-checking, changed __…
Browse files Browse the repository at this point in the history
…curveFit from scipy.optimize() to numpy.polyfit(), disabled travis e-mail notification
  • Loading branch information
nspi committed Sep 4, 2016
1 parent fc35959 commit 2768f68
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.idea/
5 changes: 4 additions & 1 deletion .travis.yml
Expand Up @@ -15,4 +15,7 @@ install:
python:
- "2.7"

script: "nosetests"
script: "nosetests"

notifications:
email: false
187 changes: 187 additions & 0 deletions src/data/LOGFILE
Expand Up @@ -140,3 +140,190 @@
03.09.2016 01:10:12 gui_toolbarButtons DEBUG [<_MainThread(MainThread, started 139977439106880)>, <VideoThread(Thread-1, started 139976792540928)>, <GuiSignalProcessor(Thread-8, started 139976737269504)>, <GuiSignalPlotter(Thread-7, started 139976745662208)>]
03.09.2016 01:10:12 gui_toolbarButtons INFO Program will halt now...
03.09.2016 01:10:12 gui_signalProcessor INFO Reached end of signal processing thread
04.09.2016 10:20:11 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 10:20:11 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 10:20:11 gui INFO Created status bar
04.09.2016 10:20:11 gui INFO Created toolbar for ROI definition
04.09.2016 10:20:11 gui INFO Created part of the GUI that shows video
04.09.2016 10:20:12 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 10:20:12 gui INFO Created toolbar with buttons
04.09.2016 10:20:12 gui INFO Main window was created
04.09.2016 10:20:12 gui INFO Starting TkInter main loop
04.09.2016 10:20:32 gui_toolbarButtons INFO Start button has been pressed
04.09.2016 10:20:32 gui_toolbarButtons INFO Camera is started
04.09.2016 10:20:32 video INFO Camera index was set because user pressed start button
04.09.2016 10:20:32 gui_toolbarButtons INFO Enabling event: eventCameraChosen
04.09.2016 10:20:32 video INFO User pressed start and wants to use the camera
04.09.2016 10:20:32 video INFO The camera was initialized
04.09.2016 10:20:32 gui_windowVideo INFO First frame from webcam was received and ROI was adjusted
04.09.2016 10:20:37 settings INFO Parameter: 5 was changed
04.09.2016 10:20:37 gui_toolbarROI INFO Viola-Jones algorithm was activated by the user
04.09.2016 10:20:38 settings INFO Parameter: 5 was changed
04.09.2016 10:20:38 gui_toolbarROI INFO Viola-Jones algorithm was disabled by the user
04.09.2016 10:20:40 settings INFO Parameter: 5 was changed
04.09.2016 10:20:40 gui_toolbarROI INFO Viola-Jones algorithm was activated by the user
04.09.2016 10:20:44 settings INFO Parameter: 5 was changed
04.09.2016 10:20:44 gui_toolbarROI INFO Viola-Jones algorithm was disabled by the user
04.09.2016 13:45:21 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 13:45:21 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 13:45:21 gui INFO Created status bar
04.09.2016 13:45:21 gui INFO Created toolbar for ROI definition
04.09.2016 13:45:21 gui INFO Created part of the GUI that shows video
04.09.2016 13:45:21 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 13:45:21 gui INFO Created toolbar with buttons
04.09.2016 13:45:21 gui INFO Main window was created
04.09.2016 13:45:21 gui INFO Starting TkInter main loop
04.09.2016 13:45:26 gui_toolbarButtons INFO Start button has been pressed
04.09.2016 13:45:26 gui_toolbarButtons INFO Camera is started
04.09.2016 13:45:26 video INFO Camera index was set because user pressed start button
04.09.2016 13:45:26 gui_toolbarButtons INFO Enabling event: eventCameraChosen
04.09.2016 13:45:26 video INFO User pressed start and wants to use the camera
04.09.2016 13:45:26 video INFO The camera was initialized
04.09.2016 13:45:26 gui_windowVideo INFO First frame from webcam was received and ROI was adjusted
04.09.2016 13:45:28 settings INFO Parameter: 5 was changed
04.09.2016 13:45:28 gui_toolbarROI INFO Viola-Jones algorithm was activated by the user
04.09.2016 13:45:31 settings INFO Parameter: 5 was changed
04.09.2016 13:45:31 gui_toolbarROI INFO Viola-Jones algorithm was disabled by the user
04.09.2016 13:46:08 settings INFO Parameter: 5 was changed
04.09.2016 13:46:08 gui_toolbarROI INFO Viola-Jones algorithm was activated by the user
04.09.2016 13:46:10 settings INFO Parameter: 5 was changed
04.09.2016 13:46:10 gui_toolbarROI INFO Viola-Jones algorithm was disabled by the user
04.09.2016 13:46:10 settings INFO Parameter: 5 was changed
04.09.2016 13:46:10 gui_toolbarROI INFO Viola-Jones algorithm was activated by the user
04.09.2016 13:46:12 settings INFO Parameter: 5 was changed
04.09.2016 13:46:12 gui_toolbarROI INFO Viola-Jones algorithm was disabled by the user
04.09.2016 13:46:24 gui_toolbarButtons INFO User pressed ''quit'' button - now halting threads
04.09.2016 13:46:24 gui_toolbarButtons INFO Signal display thread was closed
04.09.2016 13:46:24 gui_toolbarButtons INFO Camera capture thread was closed
04.09.2016 13:46:24 gui_toolbarButtons INFO Tk mainloop() was halted
04.09.2016 13:46:24 gui_toolbarButtons DEBUG [<_MainThread(MainThread, started 140495370209088)>, <VideoThread(Thread-1, started 140494723643136)>, <GuiSignalProcessor(Thread-8, started 140494668371712)>, <GuiSignalPlotter(Thread-7, started 140494676764416)>]
04.09.2016 13:46:24 gui_toolbarButtons INFO Program will halt now...
04.09.2016 13:46:24 video INFO The camera was released
04.09.2016 13:46:24 gui_signalProcessor INFO Reached end of signal processing thread
04.09.2016 13:54:00 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 13:54:00 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 13:54:00 gui INFO Created status bar
04.09.2016 13:54:00 gui INFO Created toolbar for ROI definition
04.09.2016 13:54:00 gui INFO Created part of the GUI that shows video
04.09.2016 13:54:00 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 13:54:00 gui INFO Created toolbar with buttons
04.09.2016 13:54:00 gui INFO Main window was created
04.09.2016 13:54:00 gui INFO Starting TkInter main loop
04.09.2016 13:54:02 gui_toolbarButtons INFO User pressed ''quit'' button - now halting threads
04.09.2016 13:54:02 gui_toolbarButtons INFO Signal display thread was closed
04.09.2016 13:54:02 gui_toolbarButtons INFO Camera capture thread was closed
04.09.2016 13:54:02 gui_toolbarButtons INFO Tk mainloop() was halted
04.09.2016 13:54:02 gui_toolbarButtons DEBUG [<_MainThread(MainThread, started 140633930327872)>, <VideoThread(Thread-1, started 140633283761920)>, <GuiSignalPlotter(Thread-7, started 140633236883200)>, <GuiSignalProcessor(Thread-8, started 140633228490496)>]
04.09.2016 13:54:02 gui_toolbarButtons INFO Program will halt now...
04.09.2016 13:54:02 gui_signalProcessor INFO Reached end of signal processing thread
04.09.2016 14:54:04 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 14:54:04 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 14:54:04 gui INFO Created status bar
04.09.2016 14:54:04 gui INFO Created toolbar for ROI definition
04.09.2016 14:54:04 gui INFO Created part of the GUI that shows video
04.09.2016 14:54:04 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 14:54:04 gui INFO Created toolbar with buttons
04.09.2016 14:54:04 gui INFO Main window was created
04.09.2016 14:54:04 gui INFO Starting TkInter main loop
04.09.2016 14:54:21 gui_toolbarButtons INFO User has chosen valid directory with images
04.09.2016 14:54:22 gui_toolbarButtons INFO Files have been loaded successfully.
04.09.2016 14:54:23 gui_toolbarButtons INFO Start button has been pressed
04.09.2016 14:54:23 gui_toolbarButtons INFO Camera is started
04.09.2016 14:54:23 video INFO Camera index was set because user pressed start button
04.09.2016 14:54:23 gui_toolbarButtons INFO Enabling event: eventCameraChosen
04.09.2016 14:54:23 video INFO User pressed start and wants to use frames from hard disk
04.09.2016 14:54:23 gui_windowVideo INFO First frame from webcam was received and ROI was adjusted
04.09.2016 14:54:37 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 14:54:37 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 14:54:37 gui INFO Created status bar
04.09.2016 14:54:37 gui INFO Created toolbar for ROI definition
04.09.2016 14:54:38 gui INFO Created part of the GUI that shows video
04.09.2016 14:54:38 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 14:54:38 gui INFO Created toolbar with buttons
04.09.2016 14:54:38 gui INFO Main window was created
04.09.2016 14:54:38 gui INFO Starting TkInter main loop
04.09.2016 14:54:48 gui_toolbarButtons INFO User has chosen valid directory with images
04.09.2016 14:54:48 gui_toolbarButtons INFO Files have been loaded successfully.
04.09.2016 14:54:49 gui_toolbarButtons INFO Start button has been pressed
04.09.2016 14:54:49 gui_toolbarButtons INFO Camera is started
04.09.2016 14:54:49 video INFO Camera index was set because user pressed start button
04.09.2016 14:54:49 gui_toolbarButtons INFO Enabling event: eventCameraChosen
04.09.2016 14:54:49 video INFO User pressed start and wants to use frames from hard disk
04.09.2016 14:54:49 gui_windowVideo INFO First frame from webcam was received and ROI was adjusted
04.09.2016 14:55:20 settings WARNING Unexpected error when reading configuration. Trying again.
04.09.2016 14:55:33 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 14:55:33 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 14:55:33 gui INFO Created status bar
04.09.2016 14:55:33 gui INFO Created toolbar for ROI definition
04.09.2016 14:55:33 gui INFO Created part of the GUI that shows video
04.09.2016 14:55:33 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 14:55:33 gui INFO Created toolbar with buttons
04.09.2016 14:55:33 gui INFO Main window was created
04.09.2016 14:55:33 gui INFO Starting TkInter main loop
04.09.2016 14:55:45 gui_toolbarButtons INFO User has chosen valid directory with images
04.09.2016 14:55:46 gui_toolbarButtons INFO Files have been loaded successfully.
04.09.2016 14:55:47 gui_toolbarButtons INFO Start button has been pressed
04.09.2016 14:55:47 gui_toolbarButtons INFO Camera is started
04.09.2016 14:55:47 video INFO Camera index was set because user pressed start button
04.09.2016 14:55:47 gui_toolbarButtons INFO Enabling event: eventCameraChosen
04.09.2016 14:55:47 video INFO User pressed start and wants to use frames from hard disk
04.09.2016 14:55:47 gui_windowVideo INFO First frame from webcam was received and ROI was adjusted
04.09.2016 14:56:11 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 14:56:11 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 14:56:11 gui INFO Created status bar
04.09.2016 14:56:11 gui INFO Created toolbar for ROI definition
04.09.2016 14:56:11 gui INFO Created part of the GUI that shows video
04.09.2016 14:56:11 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 14:56:11 gui INFO Created toolbar with buttons
04.09.2016 14:56:11 gui INFO Main window was created
04.09.2016 14:56:11 gui INFO Starting TkInter main loop
04.09.2016 14:56:23 gui_toolbarButtons INFO User has chosen valid directory with images
04.09.2016 14:56:24 gui_toolbarButtons INFO Files have been loaded successfully.
04.09.2016 14:56:24 gui_toolbarButtons INFO Start button has been pressed
04.09.2016 14:56:24 gui_toolbarButtons INFO Camera is started
04.09.2016 14:56:24 video INFO Camera index was set because user pressed start button
04.09.2016 14:56:24 gui_toolbarButtons INFO Enabling event: eventCameraChosen
04.09.2016 14:56:25 video INFO User pressed start and wants to use frames from hard disk
04.09.2016 14:56:25 gui_windowVideo INFO First frame from webcam was received and ROI was adjusted
04.09.2016 14:56:34 gui_toolbarROI WARNING Your ROI definition was inadequate (y_min < y_max). The values were corrected.
04.09.2016 14:56:54 settings WARNING Unexpected error when reading configuration. Trying again.
04.09.2016 14:59:20 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 14:59:20 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 14:59:20 gui INFO Created status bar
04.09.2016 14:59:20 gui INFO Created toolbar for ROI definition
04.09.2016 14:59:20 gui INFO Created part of the GUI that shows video
04.09.2016 14:59:20 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 14:59:21 gui INFO Created toolbar with buttons
04.09.2016 14:59:21 gui INFO Main window was created
04.09.2016 14:59:21 gui INFO Starting TkInter main loop
04.09.2016 14:59:31 gui_toolbarButtons INFO User has chosen valid directory with images
04.09.2016 14:59:32 gui_toolbarButtons INFO Files have been loaded successfully.
04.09.2016 14:59:32 gui_toolbarButtons INFO Start button has been pressed
04.09.2016 14:59:32 gui_toolbarButtons INFO Camera is started
04.09.2016 14:59:32 video INFO Camera index was set because user pressed start button
04.09.2016 14:59:32 gui_toolbarButtons INFO Enabling event: eventCameraChosen
04.09.2016 14:59:32 video INFO User pressed start and wants to use frames from hard disk
04.09.2016 14:59:32 gui_windowVideo INFO First frame from webcam was received and ROI was adjusted
04.09.2016 15:00:07 gui_toolbarButtons INFO User pressed ''quit'' button - now halting threads
04.09.2016 15:00:07 gui_toolbarButtons INFO Signal display thread was closed
04.09.2016 15:00:07 gui_signalProcessor INFO Reached end of signal processing thread
04.09.2016 15:00:07 gui_toolbarButtons INFO Camera capture thread was closed
04.09.2016 15:00:07 gui_toolbarButtons INFO Tk mainloop() was halted
04.09.2016 15:00:07 gui_toolbarButtons DEBUG [<_MainThread(MainThread, started 139901600790336)>, <VideoThread(Thread-1, started 139901092853504)>, <GuiSignalPlotter(Thread-7, started 139901045974784)>]
04.09.2016 15:00:07 gui_toolbarButtons INFO Program will halt now...
04.09.2016 15:01:11 video INFO Found 1 OpenCV-compatible cameras
04.09.2016 15:01:11 gui INFO Link to thread that delivers video frames was stored in GUI thread
04.09.2016 15:01:11 gui INFO Created status bar
04.09.2016 15:01:11 gui INFO Created toolbar for ROI definition
04.09.2016 15:01:11 gui INFO Created part of the GUI that shows video
04.09.2016 15:01:12 gui INFO Created part of the GUI that shows the signal extracted from the video
04.09.2016 15:01:12 gui INFO Created toolbar with buttons
04.09.2016 15:01:12 gui INFO Main window was created
04.09.2016 15:01:12 gui INFO Starting TkInter main loop
04.09.2016 15:01:14 gui_toolbarButtons INFO User pressed ''quit'' button - now halting threads
04.09.2016 15:01:14 gui_toolbarButtons INFO Signal display thread was closed
04.09.2016 15:01:14 gui_toolbarButtons INFO Camera capture thread was closed
04.09.2016 15:01:14 gui_toolbarButtons INFO Tk mainloop() was halted
04.09.2016 15:01:14 gui_toolbarButtons DEBUG [<_MainThread(MainThread, started 139989756749632)>, <VideoThread(Thread-1, started 139989248812800)>, <GuiSignalPlotter(Thread-7, started 139989201934080)>, <GuiSignalProcessor(Thread-8, started 139989193541376)>]
04.09.2016 15:01:14 gui_toolbarButtons INFO Program will halt now...
04.09.2016 15:01:14 gui_signalProcessor INFO Reached end of signal processing thread
2 changes: 1 addition & 1 deletion src/gui_signalPlotter.py
Expand Up @@ -102,7 +102,7 @@ def run(self):
self.subplotInstanceBottom.plot(self.spectrumAxis, self.valuesOutput2)
self.subplotInstanceBottom.plot(self.spectrumAxis[self.spectrumMax],
self.valuesOutput2[self.spectrumMax], 'r*')
# Otherwise, plot placehoder
# Otherwise, plot placeholder
else:
self.subplotInstanceBottom.plot(self.valuesOutput2)

Expand Down
3 changes: 1 addition & 2 deletions src/gui_signalProcessor.py
Expand Up @@ -79,8 +79,7 @@ def __waitToAdjustFPS(self, startTime, endTime):
if int(self.waitTime*1000) > 0:
cv2.waitKey(int(self.waitTime * 1000))
elif int(self.waitTime*1000) == 0:
cv2.waitKey(33) # cv2.waitKey(0) results in error

cv2.waitKey(33) # cv2.waitKey(0) results in error

def run(self):
"""The main functionality of the thread: The signal is obtained and plotted"""
Expand Down
2 changes: 1 addition & 1 deletion src/gui_toolbarROI.py
Expand Up @@ -179,7 +179,7 @@ def getROI(self):
return self.x_min, self.x_max, self.y_min, self.y_max

def setROI(self, x_min, x_max, y_min, y_max):
"""Sets ROI to new defintion"""
"""Sets ROI to new definition"""
self.x_min = x_min
self.textbox_x1.delete(1.0, Tk.END)
self.textbox_x1.insert(Tk.END, self.x_min)
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ini
Expand Up @@ -4,7 +4,7 @@ bool_use_webcam = 1.0
# use which camera port?
idx_camera = 1.0
# use which algorithm?
idx_algorithm = 0.0
idx_algorithm = 1.0
# show curves?
bool_show_curves = 1.0
# store frames on hard disk?
Expand Down
24 changes: 6 additions & 18 deletions src/signal_processing.py
Expand Up @@ -4,8 +4,6 @@

import numpy as np
import datetime
import scipy.optimize as sci
import scipy.signal as sig


class SignalProcessor:
Expand All @@ -20,7 +18,6 @@ def __init__(self):
# Get time for filterWaveform() algorithm
self.currTime = datetime.datetime.now()


def filterWaveform(self, inputRawSignal, inputOutputSignal, inputParam1, inputParam2, inputParam3):
"""This function filters the video signal and thereby obtains a waveform more similar to pulse oximetry.
This is a real-time implementation of the algorithm described in:
Expand Down Expand Up @@ -56,7 +53,7 @@ def filterWaveform(self, inputRawSignal, inputOutputSignal, inputParam1, inputPa
valueM = self.__curveFit(valuesXdata, valuesNormDiffWindow)

# Get output: Computed signal
OutputSignal = np.append(OutputSignal, valueM[1])
OutputSignal = np.append(OutputSignal, valueM[0])

# Apply running max window
valueRunningMax = np.amax(OutputSignal[-inputParam1:])
Expand Down Expand Up @@ -93,8 +90,8 @@ def computeHR(self, inputRawSignal, estimatedFPS):
Proceedings of the 49th Annual Conference of the German Society for Biomedical Engineering, Luebeck, Germany,
16.-18.09.2015.
Plese note that the different length of the input signal N and that a moving average filter as described in
section 2.4) of the referenec is not applied.
Please note that the different length of the input signal N and that a moving average filter as described in
section 2.4) of the reference is not applied.
"""

# Get normalized signal
Expand Down Expand Up @@ -135,7 +132,7 @@ def computeHR(self, inputRawSignal, estimatedFPS):
limitsBool = (hrMin < freqAxis) & (hrMax > freqAxis)
limitsIdx = np.linspace(0, N - 1, N)

# Get indices of frequncies between hrMin and hrMax
# Get indices of frequencies between hrMin and hrMax
limits = limitsIdx[limitsBool.nonzero()]
limits = limits.astype(int)

Expand All @@ -151,7 +148,7 @@ def normalize(self, inputSignal):

outputSignal = inputSignal

# Prohobit dividing by zero
# Prohibit dividing by zero
if np.max(np.abs(outputSignal)) > 0:
maxVal = np.max(np.abs(outputSignal))
minVal = np.min(np.abs(outputSignal))
Expand All @@ -165,26 +162,17 @@ def __curveFit(self, inputSignal1, inputSignal2):
"""perform curve fitting and return slope value"""

# Todo: Add gaussian weights

# Perform curve fit with weighted signal
m, ret = sci.curve_fit(self.__curveFitFunc, inputSignal1, inputSignal2)
m = np.polyfit(inputSignal1, inputSignal2, 1)

return m


def __curveFitFunc(self, x, a, b):
""""linear curve fit function"""
return a * x + b


def nextpow2(self, number):
"""Simple implementation of MATLAB nextpow2 """
currValue = 2
while currValue <= number:
currValue = currValue * 2
return currValue


def computeZeroPaddingValues(self, number):
"""During zero padding, we want to fill zeros before and after signal.
This function computes the number of zeros"""
Expand Down

0 comments on commit 2768f68

Please sign in to comment.