Example #1
0
    def remove_from_database(self, glyphs):
        """**remove_from_database** (ImageList *glyphs*)

  Removes the given glyphs from the classifier training data.  Ignores silently
  if a given glyph is not in the training data.
  """
        glyphs = util.make_sequence(glyphs)
        for glyph in glyphs:
            if glyph in self.database:
                self.database.remove(glyph)
Example #2
0
    def remove_from_database(self, glyphs):
        """**remove_from_database** (ImageList *glyphs*)

Removes the given glyphs from the classifier training data.  Ignores silently
if a given glyph is not in the training data.
"""
        glyphs = util.make_sequence(glyphs)
        for glyph in glyphs:
            if glyph in self.database:
                self.database.remove(glyph)
Example #3
0
File: core.py Project: DDMAL/Gamera
    def get_feature_functions(cls, features="all"):
        from gamera import plugin

        global all_features
        if all_features is None:
            all_features = plugin.methods_flat_category("Features", ONEBIT)
            all_features.sort()
        if features == "all" or features is None:
            functions = all_features
            return functions, cls._get_feature_vector_size(functions)
        features = util.make_sequence(features)
        all_strings = True
        for feature in features:
            if not util.is_string_or_unicode(feature):
                all_strings = False
                break
        if not all_strings:
            import plugin

            all_functions = False
            if (
                type(features) == tuple
                and len(features) == 2
                and type(features[0]) == list
                and type(features[1]) == int
            ):
                all_functions = True
                for feature in features[0]:
                    if not (
                        type(feature) == tuple
                        and util.is_string_or_unicode(feature[0])
                        and issubclass(feature[1], plugin.PluginFunction)
                    ):
                        all_functions = False
                        break
            if not all_functions:
                raise ValueError("'%s' is not a valid way to specify a list of features." % str(features))
            else:
                return features
        else:
            features.sort()
            functions = []
            for feature in features:
                found = 0
                for i in all_features:
                    if feature == i[0]:
                        functions.append(i)
                        found = 1
                        break
                if not found:
                    raise ValueError("'%s' is not a known feature function." % feature)
            functions.sort()
            return functions, cls._get_feature_vector_size(functions)
Example #4
0
    def add_to_database(self, glyphs):
        """**add_to_database** (ImageList *glyphs*)

Adds the given glyph (or list of glyphs) to the classifier training data.  Will not add duplicates
to the training data.  Unlike classify_glyph_manual_, no grouping support is performed.
"""
        glyphs = util.make_sequence(glyphs)
        new_glyphs = []
        for glyph in glyphs:
            if (glyph.classification_state == core.MANUAL
                    and not glyph in self.database):
                self.generate_features(glyph)
                new_glyphs.append(glyph)
        self.database.extend(new_glyphs)
Example #5
0
    def add_to_database(self, glyphs):
        """**add_to_database** (ImageList *glyphs*)

  Adds the given glyph (or list of glyphs) to the classifier training data.  Will not add duplicates
  to the training data.  Unlike classify_glyph_manual_, no grouping support is performed.
  """
        glyphs = util.make_sequence(glyphs)
        new_glyphs = []
        for glyph in glyphs:
            if (glyph.classification_state == core.MANUAL and
                not glyph in self.database):
                self.generate_features(glyph)
                new_glyphs.append(glyph)
        self.database.extend(new_glyphs)
Example #6
0
 def __init__(self, glyphs, max_width=100, max_height=100):
    """Creates a grid index to store the given set of glyphs.  Note that
    the init function only creates a grid big enough to hold the glyphs,
    it does not actually store them...  That must be done by calling
    GridIndex.add_glyph.  max_width and max_height are the maximum size
    (in pixels) of each cell."""
    glyphs = util.make_sequence(glyphs)
    if len(glyphs) == 0:
       raise ValueError(
           "GridIndex must be initialised with at least one glyph")
    self.grid_rect = glyphs[0].union_rects(glyphs)
    self.cell_width = int(max_width)
    self.cell_height = int(max_height)
    self.cell_ncols = int(self.grid_rect.width / self.cell_width) + 1
    self.cell_nrows = int(self.grid_rect.height / self.cell_height) + 1
    self._create_cells()
Example #7
0
 def get_feature_functions(cls, features='all'):
     global all_features
     if all_features is None:
         all_features = plugin.methods_flat_category('Features', ONEBIT)
         all_features.sort()
     if features == 'all' or features is None:
         functions = all_features
         return functions, cls._get_feature_vector_size(functions)
     features = util.make_sequence(features)
     all_strings = True
     for feature in features:
         if not util.is_string_or_unicode(feature):
             all_strings = False
             break
     if not all_strings:
         all_functions = False
         if (type(features) == tuple and len(features) == 2
                 and type(features[0]) == list
                 and type(features[1]) == int):
             all_functions = True
         for feature in features[0]:
             if not (type(feature) == tuple
                     and util.is_string_or_unicode(feature[0])
                     and issubclass(feature[1], plugin.PluginFunction)):
                 all_functions = False
                 break
         if not all_functions:
             raise ValueError(
                 "'%s' is not a valid way to specify a list of features." %
                 str(features))
         else:
             return features
     else:
         features.sort()
         functions = []
         for feature in features:
             found = 0
             for i in all_features:
                 if feature == i[0]:
                     functions.append(i)
                     found = 1
                 break
             if not found:
                 raise ValueError("'%s' is not a known feature function." %
                                  feature)
         functions.sort()
         return functions, cls._get_feature_vector_size(functions)
Example #8
0
 def merge_glyphs(self, glyphs):
     glyphs = util.make_sequence(glyphs)
     self.generate_features_on_glyphs(glyphs)
     self.database.extend(glyphs)
Example #9
0
 def set_glyphs(self, glyphs):
     glyphs = util.make_sequence(glyphs)
     self.clear_glyphs()
     self.generate_features_on_glyphs(glyphs)
     self.database.extend(glyphs)
Example #10
0
File: args.py Project: DDMAL/Gamera
 def __init__(self, list=[], name="Arguments", function=None, title=None):
     self.list = util.make_sequence(list)
     self.valid = 1
     self.name = name
     self.function = function
     self.title = title
Example #11
0
 def merge_glyphs(self, glyphs):
     glyphs = util.make_sequence(glyphs)
     self.generate_features_on_glyphs(glyphs)
     self.database.extend(glyphs)
Example #12
0
 def set_glyphs(self, glyphs):
     glyphs = util.make_sequence(glyphs)
     self.clear_glyphs()
     self.generate_features_on_glyphs(glyphs)
     self.database.extend(glyphs)
Example #13
0
 def __init__(self, list=[], name="Arguments", function=None, title=None):
     self.list = util.make_sequence(list)
     self.valid = 1
     self.name = name
     self.function = function
     self.title = title