-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
190 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.