Skip to content

Commit

Permalink
Merge branch 'augoust-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pyskell committed Oct 30, 2015
2 parents 2c82c16 + 6f00785 commit 80e2be4
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 127 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You need to install the following system-wide:

* Python 2.7
* [Qt4](http://doc.qt.io/qt-4.8/installation.html) and [PyQt4](http://pyqt.sourceforge.net/Docs/PyQt4/installation.html)
* [OpenCV](http://docs.opencv.org/doc/tutorials/introduction/table_of_content_introduction/table_of_content_introduction.html)
* [OpenCV 2 or 3](http://docs.opencv.org/doc/tutorials/introduction/table_of_content_introduction/table_of_content_introduction.html)
* [OpenCV-Python](https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_setup/py_table_of_contents_setup/py_table_of_contents_setup.html#py-table-of-content-setup)

## Debian Dependencies
Expand Down
43 changes: 43 additions & 0 deletions arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from argparse import ArgumentParser

def get_arguments():
parser = ArgumentParser(description = 'Slouchy uses your webcam t'
'o determine if you are slouching and alerts you when you'
'are. This project is still in active development and not'
'feature complete.')

# Flags
ui_mode = parser.add_mutually_exclusive_group()
ui_mode.add_argument('--text-mode', '-t', action = 'store_true',
help = 'Put slouchy in text mode, disabling all GUI features.')
ui_mode.add_argument('--gui', '-g', action = 'store_true',
help = 'Put slouchy in GUI mode (the default). GUI mode normally')

# Settings overrides
parser.add_argument('--config-file', '-s', type = str,
help = 'The location of a config file for slouchy.')
parser.add_argument('--video-device', '-d', type = str,
help = 'Value for specifying the camera to use.')
parser.add_argument('--poll-rate', '-p', type = int,
help = 'Time to wait between checking user posture.')
parser.add_argument('--camera-warm-up', '-w', type = int,
help = 'Time needed for the user camera to initialize.')
parser.add_argument('--distance-reference', '-r', type = float,
help = 'The face-to-camera distance value of the subject '
'when sitting upright. Due to the geometrical limi'
'ts spinal mobility, this is used as a proxy for d'
'etecting slouching.')
parser.add_argument('--thoracolumbar-tolerance', '-l', type = float,
help = 'The amount of deviation from the reference which'
' will be tolerated before registering the lower a'
'nd mid back of the subject is slouching.')
parser.add_argument('--cervical-tolerance', '-c', type = float,
help = 'The amount lateral flexion of the cervical before'
' registering poor neck posture.')
parser.add_argument('--face-cascade-path', '-f', type = str,
help = 'The path of a face cascade clasifier.')
parser.add_argument('--eye-cascade-path', '-e', type = str,
help = 'The path of an eye cascade clasifier.')

return parser.parse_args()
52 changes: 35 additions & 17 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
# -*- coding: utf-8 -*-
from configobj import ConfigObj

# Local imports
from main import video_device, determine_posture, take_picture #, detect_face
# Local import
from arg import get_arguments

# Set initial values
def setup():
config = ConfigObj('slouchy.ini')
# Get all command-line arguments. arg.get_arguments() returns a Namespace
# object containg True or False values for the interface mode (GUI or CLI)
# and numeric/string values for selectively overiding the slouchy.ini settings
args = get_arguments()

maybe_image = take_picture(video_device)
# maybe_face = detect_face(maybe_image)
maybe_current_posture = determine_posture(maybe_image)
# Determine if the user wants status output on the command line
text_mode = args.text_mode

if maybe_current_posture.success:
config['MAIN']['posture_reference'] = str(maybe_current_posture.result.get('distance'))
print("Reference value detected as:", maybe_current_posture.result)
else:
print("Error:", maybe_current_posture.result)
return maybe_current_posture
# Load settings from the config file (default to slouchy.ini)
if args.config_file:
config_file = ConfigObj(args.config_file)
else:
config_file = ConfigObj('slouchy.ini')

config.write()
# Dict-ize args (for looping)
args = vars(args)

if __name__ == '__main__':
setup()
# Overide config file settings per the command line
for key, val in args.iteritems():
if key in config_file['MAIN'].keys():
globals()[key] = args[key] if args[key] else config_file['MAIN'][key]

# Some settings need to be floats (not strings)
for i in ['distance_reference', 'thoracolumbar_tolerance',\
'cervical_tolerance', 'camera_warm_up']:
globals()[i] = float(globals()[i])

# poll_rate needs to be an int
globals()['poll_rate'] = int(globals()['poll_rate'])

# video_device can be either an int or str, so try int but fall back on str
video_device = globals()['video_device']
try:
video_device = int(video_device)
except ValueError:
video_device = str(video_device)
Loading

0 comments on commit 80e2be4

Please sign in to comment.