[mousetrap/gnome3-wip: 215/240] Adjust key used to cache FeatureDetectors.



commit 03eb16f547f947e6e47f7493df3fe3ba02f91a1b
Author: Stoney Jackson <dr stoney gmail com>
Date:   Sun Jun 29 17:00:50 2014 -0400

    Adjust key used to cache FeatureDetectors.
    
    Considering the name is only unique to the haar file used and not
    the arguments (such as the scale factor or minimum neighbours),
    we should be storing the combination based on a different key.

 src/mousetrap/vision.py |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/src/mousetrap/vision.py b/src/mousetrap/vision.py
index 3ea0cf8..5fddc7b 100644
--- a/src/mousetrap/vision.py
+++ b/src/mousetrap/vision.py
@@ -93,16 +93,17 @@ class FeatureDetector(object):
 
     @classmethod
     def get_detector(cls, config, name, scale_factor=1.1, min_neighbors=3):
-        if name in cls._INSTANCES:
-            LOGGER.info("Reusing %s detector." % name)
-            return cls._INSTANCES[name]
-        cls._INSTANCES[name] = FeatureDetector(
+        key = (name, scale_factor, min_neighbors)
+        if key in cls._INSTANCES:
+            LOGGER.info("Reusing %s detector.", key)
+            return cls._INSTANCES[key]
+        cls._INSTANCES[key] = FeatureDetector(
                 config, name, scale_factor, min_neighbors)
-        return cls._INSTANCES[name]
+        return cls._INSTANCES[key]
 
     @classmethod
     def clear_all_detection_caches(cls):
-        for name, instance in cls._INSTANCES.items():
+        for key, instance in cls._INSTANCES.items():
             instance.clear_cache()
 
     def __init__(self, config, name, scale_factor=1.1, min_neighbors=3):
@@ -115,7 +116,7 @@ class FeatureDetector(object):
         min_neighbors - how many neighbors each candidate rectangle should have
                 to retain it. Default 3.
         '''
-        LOGGER.info("Building %s detector." % name)
+        LOGGER.info("Building detector: %s", (name, scale_factor, min_neighbors))
         self._config = config
         self._name = name
         self._single = None


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