示例#1
0
文件: core.py 项目: 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)
示例#2
0
 def get(self):
    selection = self.control.GetSelection()
    if (len(self.choices[selection]) == 2 and
        not util.is_string_or_unicode(self.choices[selection])):
       return self.choices[selection][1]
    else:
       return int(selection)
示例#3
0
文件: core.py 项目: alan0526/Gamera
    def classify_automatic(self, id_name):
        """Classifies the image as the value *id_name* and sets the state
to AUTOMATIC.  Use this method when an automatic classifier has classified
this glyph. Note that this method does not touch the *confidence* map for
the main id; this must be set separately.

*id_name*
  Can come in one of two forms:

    **string**
       image is classified using the given ``.``-delimited class name.
       As in this case no confidence is provided, it is set to zero.
    **list of tuples**
       A list of tuples where each tuple is the pair (*confidence*, *class_name*).

       *confidence*
         A value in range (0, 1), where 0 is uncertain and 1 is certain.
       *class_name*
         A ``.``-delimited class name."""
        if util.is_string_or_unicode(id_name):
            id_name = [(0.0, id_name)]
        elif type(id_name) != ListType:
            raise TypeError("id_name must be a string or a list")
        self.id_name = id_name
        self.classification_state = AUTOMATIC
示例#4
0
 def get(self):
     selection = self.control.GetSelection()
     if (len(self.choices[selection]) == 2
             and not util.is_string_or_unicode(self.choices[selection])):
         return self.choices[selection][1]
     else:
         return int(selection)
示例#5
0
文件: core.py 项目: alan0526/Gamera
    def classify_heuristic(self, id_name):
        """Classifies the image as the value *id_name* and sets the state
to HEURISTIC.  Use this method when a heuristic process has classified
this glyph. This method also unsets the *confidence* map.

*id_name*
  Can come in one of two forms:

    **string**
       image is classified using the given ``.``-delimited class name.
       As in this case no confidence is provided, it is set to 0.5.
    **list of tuples**
       A list of tuples where each tuple is the pair (*confidence*, *class_name*).

       *confidence*
         A value in range (0, 1), where 0 is uncertain and 1 is certain.
       *class_name*
         A ``.``-delimited class name."""
        if util.is_string_or_unicode(id_name):
            id_name = [(0.5, id_name)]
        elif type(id_name) != ListType:
            raise TypeError("id_name must be a string or a list")
        self.id_name = id_name
        self.confidence = {}
        self.classification_state = HEURISTIC
示例#6
0
    def classify_heuristic(self, id_name):
        """Classifies the image as the value *id_name* and sets the state
to HEURISTIC.  Use this method when a heuristic process has classified
this glyph. This method also unsets the *confidence* map.

*id_name*
  Can come in one of two forms:

    **string**
       image is classified using the given ``.``-delimited class name.
       As in this case no confidence is provided, it is set to 0.5.
    **list of tuples**
       A list of tuples where each tuple is the pair (*confidence*, *class_name*).

       *confidence*
         A value in range (0, 1), where 0 is uncertain and 1 is certain.
       *class_name*
         A ``.``-delimited class name."""
        if util.is_string_or_unicode(id_name):
            id_name = [(0.5, id_name)]
        elif type(id_name) != ListType:
            raise TypeError("id_name must be a string or a list")
        self.id_name = id_name
        self.confidence = {}
        self.classification_state = HEURISTIC
示例#7
0
 def get_control(self, parent, locals=None):
    if util.is_string_or_unicode(self.klass):
       self.klass = eval(self.klass)
    self.control = wx.Choice(
       parent, -1, choices = self.determine_choices(locals))
    #self.control.SetSelection(0)
    return self
示例#8
0
    def classify_automatic(self, id_name):
        """Classifies the image as the value *id_name* and sets the state
to AUTOMATIC.  Use this method when an automatic classifier has classified
this glyph. Note that this method does not touch the *confidence* map for
the main id; this must be set separately.

*id_name*
  Can come in one of two forms:

    **string**
       image is classified using the given ``.``-delimited class name.
       As in this case no confidence is provided, it is set to zero.
    **list of tuples**
       A list of tuples where each tuple is the pair (*confidence*, *class_name*).

       *confidence*
         A value in range (0, 1), where 0 is uncertain and 1 is certain.
       *class_name*
         A ``.``-delimited class name."""
        if util.is_string_or_unicode(id_name):
            id_name = [(0.0, id_name)]
        elif type(id_name) != ListType:
            raise TypeError("id_name must be a string or a list")
        self.id_name = id_name
        self.classification_state = AUTOMATIC
示例#9
0
 def get_control(self, parent, locals=None):
    if util.is_string_or_unicode(self.klass):
       self.klass = eval(self.klass)
    self.choices = self.determine_choices(locals)
    self.control = wx.ComboBox( 
      parent, -1, str(self.default), choices=self.choices, style=wx.CB_DROPDOWN)
    return self
示例#10
0
文件: core.py 项目: alan0526/Gamera
 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)
示例#11
0
    def __init__(self, name=None, default="", extension="*.*"):
        Arg.__init__(self, name)
        if not util.is_string_or_unicode(default):
            raise TypeError("'default' must be a string")
        self.default = default
##       if not util.is_string_or_unicode(extension):
##          raise TypeError("'extension' must be a string")
        self.extension = extension
示例#12
0
 def get_control(self, parent, locals=None):
     if util.is_string_or_unicode(self.klass):
         self.klass = eval(self.klass)
     self.control = wx.Choice(parent,
                              -1,
                              choices=self.determine_choices(locals))
     #self.control.SetSelection(0)
     return self
示例#13
0
文件: args.py 项目: DDMAL/Gamera
    def __init__(self, name=None, default="", extension="*.*"):
        Arg.__init__(self, name)
        if not util.is_string_or_unicode(default):
            raise TypeError("'default' must be a string")
        self.default = default
##       if not util.is_string_or_unicode(extension):
##          raise TypeError("'extension' must be a string")
        self.extension = extension
示例#14
0
文件: args.py 项目: DDMAL/Gamera
 def __init__(self, name=None, default=None):
     Arg.__init__(self, name)
     if default is None:
         self.has_default = False
         self.default = ''
     else:
         self.has_default = True
         self.default = default
     if not util.is_string_or_unicode(self.default):
         raise TypeError("'default' must be an int")
示例#15
0
 def get_control(self, parent, locals=None):
     if util.is_string_or_unicode(self.klass):
         self.klass = eval(self.klass)
     self.choices = self.determine_choices(locals)
     self.control = wx.ComboBox(parent,
                                -1,
                                str(self.default),
                                choices=self.choices,
                                style=wx.CB_DROPDOWN)
     return self
示例#16
0
 def __init__(self, name=None, default=None):
     Arg.__init__(self, name)
     if default is None:
         self.has_default = False
         self.default = ''
     else:
         self.has_default = True
         self.default = default
     if not util.is_string_or_unicode(self.default):
         raise TypeError("'default' must be an int")
示例#17
0
 def get_control(self, parent, locals=None):
     choices = []
     for choice in self.choices:
         if len(choice) == 2 and not util.is_string_or_unicode(choice):
             choices.append(choice[0])
         else:
             choices.append(choice)
     self.control = wx.Choice(parent, -1, choices=choices)
     if self.default < 0:
         self.default = len(choices) + self.default
     if self.default >= 0 and self.default < len(self.choices):
         self.control.SetSelection(self.default)
     return self
示例#18
0
 def __init__(self, name=None, check_box='', default=None, enabled=True):
     Arg.__init__(self, name)
     if not util.is_string_or_unicode(check_box):
         raise TypeError("'check_box' must be a string")
     self.check_box = check_box
     if default is None:
         self.has_default = False
         self.default = False
     else:
         self.has_default = True
         self.default = default
     self.default = bool(self.default)
     self.enabled = bool(enabled)
示例#19
0
 def get_control(self, parent, locals=None):
    choices = []
    for choice in self.choices:
       if len(choice) == 2 and not util.is_string_or_unicode(choice):
          choices.append(choice[0])
       else:
          choices.append(choice)
    self.control = wx.Choice(parent, -1, choices=choices)
    if self.default < 0:
       self.default = len(choices) + self.default
    if self.default >= 0 and self.default < len(self.choices):
       self.control.SetSelection(self.default)
    return self
示例#20
0
文件: args.py 项目: DDMAL/Gamera
 def __init__(self, name=None, check_box='', default=None, enabled=True):
     Arg.__init__(self, name)
     if not util.is_string_or_unicode(check_box):
         raise TypeError("'check_box' must be a string")
     self.check_box = check_box
     if default is None:
         self.has_default = False
         self.default = False
     else:
         self.has_default = True
         self.default = default
     self.default = bool(self.default)
     self.enabled = bool(enabled)
示例#21
0
 def __init__(self, message, length=1, numsteps=0):
    assert util.is_string_or_unicode(message)
    self.progress_box = wx.ProgressDialog(
       "Progress", message, 100,
       style=wx.PD_APP_MODAL|wx.PD_ELAPSED_TIME|wx.PD_REMAINING_TIME|wx.PD_AUTO_HIDE)
    self.done = 0
    self._num = 0
    if length == 0:
       self._den = 1
    else:
       self._den = length
    self._numsteps = numsteps
    self._lastupdate = 0
    wx.BeginBusyCursor()
示例#22
0
 def __init__(self, message, length=1, numsteps=0):
    assert util.is_string_or_unicode(message)
    self.progress_box = wx.ProgressDialog(
        "Progress", message, 100,
       style=wx.PD_APP_MODAL|wx.PD_ELAPSED_TIME|wx.PD_REMAINING_TIME|wx.PD_AUTO_HIDE)
    self.done = 0
    self._num = 0
    if length == 0:
       self._den = 1
    else:
       self._den = length
    self._numsteps = numsteps
    self._lastupdate = 0
    self._lasttime = datetime.datetime.now()
    wx.BeginBusyCursor()
示例#23
0
 def __init__(self, name):
     self.name = name
     if name is not None and not util.is_string_or_unicode(name):
         raise TypeError("'name' must be a string")
     self.has_default = False
示例#24
0
文件: args.py 项目: DDMAL/Gamera
 def __init__(self, name):
     self.name = name
     if name is not None and not util.is_string_or_unicode(name):
         raise TypeError("'name' must be a string")
     self.has_default = False