[mousetrap/gnome3-wip: 130/240] Extract mousetrap.plugins.eyes configuration.



commit c400152bf7af18846c49218f385bb8996d36d760
Author: Stoney Jackson <dr stoney gmail com>
Date:   Mon Jun 23 15:34:06 2014 -0400

    Extract mousetrap.plugins.eyes configuration.

 src/mousetrap/config.py       |   29 ++++++++++++++++++++++++++++-
 src/mousetrap/plugins/eyes.py |   18 +++++++++---------
 2 files changed, 37 insertions(+), 10 deletions(-)
---
diff --git a/src/mousetrap/config.py b/src/mousetrap/config.py
index 9d4c026..25e0fcf 100644
--- a/src/mousetrap/config.py
+++ b/src/mousetrap/config.py
@@ -49,9 +49,36 @@ class Config(dict):
         self['classes'] = {
             'mousetrap.plugins.display.DisplayPlugin': {
                 'window_title': 'MouseTrap',
-                }
+                },
+
+            'mousetrap.plugins.eyes.MotionDetector': {
+                'max_samples': 5,
+                },
+
+            'mousetrap.plugins.eyes.ClosedDetector': {
+                'max_samples': 15,
+                'min_fraction_to_be_closed': 0.8,
+                },
+
+            'mousetrap.plugins.eyes.LeftEyeLocator': {
+                'face_detector': {
+                    'scale_factor': 1.5,
+                    'min_neighbors': 5,
+                    },
+
+                'open_eye_detector': {
+                    'scale_factor': 1.1,
+                    'min_neighbors': 3,
+                    },
+
+                'left_eye_detector': {
+                    'scale_factor': 1.5,
+                    'min_neighbors': 10,
+                    },
+                },
             }
 
+
     def __getitem__(self, key):
         '''
         Allow access to class configuration by passing instance of class as
diff --git a/src/mousetrap/plugins/eyes.py b/src/mousetrap/plugins/eyes.py
index 1f2ce0d..2d2b7ab 100644
--- a/src/mousetrap/plugins/eyes.py
+++ b/src/mousetrap/plugins/eyes.py
@@ -25,7 +25,7 @@ class EyesPlugin(interface.Plugin):
 class MotionDetector(object):
     def __init__(self, config):
         self._config = config
-        self._max_samples = 5
+        self._max_samples = config[self]['max_samples']
         self._history = History(config, self._max_samples)
 
     def update(self, pointer):
@@ -39,8 +39,8 @@ class MotionDetector(object):
 class ClosedDetector(object):
     def __init__(self, config):
         self._config = config
-        self._max_samples = 15
-        self._min_fraction_to_be_closed = 0.8
+        self._max_samples = config[self]['max_samples']
+        self._min_fraction_to_be_closed = config[self]['min_fraction_to_be_closed']
         self._min_misses_to_be_closed = int(
                 self._min_fraction_to_be_closed * self._max_samples)
         self._left_locator = LeftEyeLocator(config)
@@ -64,20 +64,20 @@ class LeftEyeLocator(object):
         self._face_detector = FeatureDetector(
                 config,
                 "face",
-                scale_factor=1.5,
-                min_neighbors=5,
+                scale_factor=config[self]['face_detector']['scale_factor'],
+                min_neighbors=config[self]['face_detector']['min_neighbors']
                 )
         self._open_eye_detector = FeatureDetector(
                 config,
                 "open_eye",
-                scale_factor=1.1,
-                min_neighbors=3,
+                scale_factor=config[self]['open_eye_detector']['scale_factor'],
+                min_neighbors=config[self]['open_eye_detector']['min_neighbors']
                 )
         self._left_eye_detector = FeatureDetector(
                 config,
                 "left_eye",
-                scale_factor=1.5,
-                min_neighbors=10,
+                scale_factor=config[self]['left_eye_detector']['scale_factor'],
+                min_neighbors=config[self]['left_eye_detector']['min_neighbors']
                 )
 
     def locate(self, image):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]