[mousetrap/gnome3-wip: 117/240] Try to improve the eye detection



commit 09250cc952e11ceac48d78820df2d28f649622e1
Author: Kevin Brown <kbrown rediker com>
Date:   Sun Jun 22 12:50:25 2014 -0400

    Try to improve the eye detection
    
    This tries to improve the eye detection by making a few critical
    changes.  With the previous changes, if the face was not detected
    the code would decide that the eye was closed and potentially fire
    a click.  With these changes, losing the face will not fire clicks.
    
    This may need to be changed a bit, as we are always defaulting to
    the eye being open.  I consider this to be a safer bet, as this
    does not cause extra unintended side effects.
    
    This also tries to detect the left eye before determining if it is
    closed.  The `haarcascade_mcs_lefteye.xml` cascade is designed to
    detect left eyes, even if they are not open, unlike the other
    cascade which will only detect open eyes.  Similar to the face
    detection, if the left eye cannot be detected it will default to
    the eye being open.
    
    Among other things, this is trying to limit the impact of the faulty
    eye detection which we need to look into fixing as per #22.
    
    https://github.com/GNOME-MouseTrap/mousetrap/issues/22

 src/mousetrap/plugins/eyes.py |   28 +++++++++++++++++++++++++---
 src/mousetrap/vision.py       |    1 +
 2 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/src/mousetrap/plugins/eyes.py b/src/mousetrap/plugins/eyes.py
index 4da6e32..6cf4543 100644
--- a/src/mousetrap/plugins/eyes.py
+++ b/src/mousetrap/plugins/eyes.py
@@ -62,17 +62,39 @@ class LeftEyeLocator(object):
             scale_factor=1.5,
             min_neighbors=5,
         )
-        self._eye_detector = FeatureDetector(
+        self._open_eye_detector = FeatureDetector(
             "open_eye",
             scale_factor=1.1,
             min_neighbors=3,
         )
+        self._left_eye_detector = FeatureDetector(
+            "left_eye",
+            scale_factor=1.5,
+            min_neighbors=10,
+        )
 
     def locate(self, image):
+        face = None
+
         try:
             face = self._face_detector.detect(image)
-            eye = self._eye_detector.detect(face["image"])
-            LOGGER.debug(eye)
+
+            LOGGER.debug("Found the face")
+        except FeatureNotFoundException:
+            return True
+
+        try:
+            left_eye = self._left_eye_detector.detect(face["image"])
+
+            LOGGER.debug("Found the left eye at %s", left_eye)
+        except FeatureNotFoundException:
+            return True
+
+        try:
+            open_eye = self._open_eye_detector.detect(face["image"])
+
+            LOGGER.debug("Found an open eye at %s", open_eye)
+
             return True
         except FeatureNotFoundException:
             return False
diff --git a/src/mousetrap/vision.py b/src/mousetrap/vision.py
index 1d6ed62..c6eaae8 100644
--- a/src/mousetrap/vision.py
+++ b/src/mousetrap/vision.py
@@ -44,6 +44,7 @@ class HaarLoader(object):
     _haar_files = {
         "face": "haars/haarcascade_frontalface_default.xml",
         "nose": "haars/haarcascade_mcs_nose.xml",
+        "left_eye": "haars/haarcascade_mcs_lefteye.xml",
         "open_eye": "haars/haarcascade_eye.xml",
     }
 


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