示例#1
0
    def init_recognizer(self,recognizer='zinnia'):
        recognizers = Recognizer.get_available_recognizers()
        print "Available recognizers", recognizers,type(recognizers)
        
        for temp in recognizers :
            pprint.pprint(temp)
        recognizer_name = recognizer
        if not recognizer_name in recognizers:
            raise Exception, "Not an available recognizer"

        recognizer_klass = recognizers[recognizer_name]
        self.recognizer = recognizer_klass()

        models = recognizer_klass.get_available_models()
        for model  in models :
            print type(model),model
        
        for model  in models :
            print type(model),model
        print "++++"
        for r_name, model_name, meta  in Recognizer.get_all_available_models() :
            print r_name
            print model_name
            print meta

        
        print "\nAvailable models", models,type(models)
        print (models['Simplified Chinese']['shortname'])
        model = "Simplified Chinese"
        if not model in models:
            raise Exception, "Not an available model"

        print self.recognizer.set_model(model)
示例#2
0
    def init_recog(self):
        self.candidates = None
        r_name, model_name, meta = Recognizer.get_all_available_models()[1]

        klass = Recognizer.get_available_recognizers()[r_name]
        self._recognizer = klass()
        self._recognizer.set_model(meta["name"])
        self._writing = Writing()
示例#3
0
 def choice_setmodel(self,nr):
     mcount = len(Recognizer.get_all_available_models())
     if (nr==mcount) and self.faking:
         self.set_decorated(not self.get_decorated())
         return
     elif nr>mcount:
         return
     r_name, model_name, meta = Recognizer.get_all_available_models()[nr]
     klass = Recognizer.get_available_recognizers()[r_name]
     self._recognizer = klass()
     self._recognizer.set_model(meta["name"])
     self._writing = Writing()
示例#4
0
    def set_selected_model(self, i):
        try:
            r_name, model_name, meta = Recognizer.get_all_available_models()[i]

            klass = Recognizer.get_available_recognizers()[r_name]
            self._recognizer = klass()
            self._recognizer.set_model(meta["name"])
            self._models_button.set_label(meta["shortname"])
            # a hack to retain the model id the button
            self._models_button.selected_model = i

            self._ready = True
        except IndexError:
            self._ready = False
示例#5
0
    def set_selected_model(self, i):
        try:
            r_name, model_name, meta = Recognizer.get_all_available_models()[i]

            klass = Recognizer.get_available_recognizers()[r_name]
            self._recognizer = klass()
            self._recognizer.set_model(meta["name"])
            self._models_button.set_label(meta["shortname"])
            # a hack to retain the model id the button
            self._models_button.selected_model = i

            self._ready = True
        except IndexError:
            self._ready = False
示例#6
0
    def post(self):
        xmlFile = request.files['file']
        recognizer = "zinnia"
        model = "Japanese"

        char = Character()
        char.read(xmlFile)
        writing = char.get_writing()

        recognizers = Recognizer.get_available_recognizers()

        if not recognizer in recognizers:
            raise TegakiRecognizeError, "Not an available recognizer."

        recognizer_klass = recognizers[recognizer]
        recognizer = recognizer_klass()

        models = recognizer_klass.get_available_models()

        if not model in models:
            raise TegakiRecognizeError, "Not an available model."

        recognizer.set_model(model)

        return {'data': recognizer.recognize(writing)}
示例#7
0
 def choice_cfg(self):
     n = []
     for r_name, model_name, meta in Recognizer.get_all_available_models():
         n += ["%s\n%s" % (r_name,model_name)]
     if self.faking:
         n += ["Toggle Window Decorations"]
     self.choice_bg_draw(n,self.DEFAULT_FONT_CFG)
示例#8
0
 def get_all_availabke_models():
     all_models = Recognizer.get_all_available_models()
     for r_name, model_name, meta in all_models :
         print(r_name)
         print(model_name)
         print(meta)
     return all_models
示例#9
0
        def setDictionary(self, recognizerSettings={}):
            #self.clear_strokes()

            #initialize the default dictionary and a simple recognizer
            if recognizerType == 'tomoe' \
                and 'tomoe' in recognizerSettings \
                and 'dictionary' in recognizerSettings['tomoe']:
                tomoeDict = Dict("XML",
                    filename=recognizerSettings['tomoe']['dictionary'])
                self.recognizer = Recognizer('Simple',
                    dictionary=tomoeDict)

                # will encapsulate stroke data
                if not self.writing:
                    self.writing = Writing()
            elif recognizerType == 'tegaki':
                recognizers = Recognizer.get_available_recognizers()

                if not recognizers:
                    raise Exception('No recognizer available')

                if 'tegaki' in recognizerSettings \
                    and 'recognizer' in recognizerSettings['tegaki']:
                    engine = recognizerSettings['tegaki']['recognizer']
                    if engine not in recognizers:
                        raise Exception('recognizer not available')
                else:
                    engine = recognizers.keys()[0]

                recognizer_klass = recognizers[engine]
                self.recognizer = recognizer_klass()

                if 'tegaki' in recognizerSettings \
                    and 'model' in recognizerSettings['tegaki']:
                    model = recognizerSettings['tegaki']['model']
                    if model not in recognizer_klass.get_available_models():
                        raise Exception('Model not available')
                else:
                    model = recognizer_klass.get_available_models().keys()[0]

                self.recognizer.set_model(model)

                # will encapsulate stroke data
                if not self.writing:
                    self.writing = Writing()
            else:
                self.writing = None
示例#10
0
文件: views.py 项目: 2050utopia/hwr
def recognize_submit(request):
    if settings.DEBUG:
        xml = request.REQUEST['xml']    #if testing we want to be able to pass stuff in with GET request
    else:
        xml = request.POST['xml']
    char = character.Character()
    char.read_string(xml)
    klass = Recognizer.get_available_recognizers()['zinnia']
    rec = klass()
    rec.set_model('Simplified Chinese')
    writing = char.get_writing()
    #writing = writing.copy()
    results = rec.recognize(writing) 
    return HttpResponse(u"%s" % jsonify_results(results))
示例#11
0
    def _create_model_menu(self):
        menu = gtk.Menu()

        all_models = Recognizer.get_all_available_models()

        if len(all_models) == 0:
            return None

        i = 0
        for r_name, model_name, meta in all_models:
            item = gtk.MenuItem("%d. %s (%s)" % (i + 1, model_name, r_name))
            item.connect("activate", self._on_activate_model, i)
            menu.append(item)
            i += 1

        return menu
示例#12
0
    def _create_model_menu(self):
        menu = gtk.Menu()

        all_models = Recognizer.get_all_available_models()

        if len(all_models) == 0:
            return None

        i = 0
        for r_name, model_name, meta in all_models:
            item = gtk.MenuItem("%d. %s (%s)" % (i+1, model_name, r_name))
            item.connect("activate", self._on_activate_model, i)
            menu.append(item)
            i += 1

        return menu
示例#13
0
    class LineDrawingGraphicsScene(QtGui.QGraphicsScene):
        """Graphics scene for drawing strokes and handling recognizer."""
        def __init__(self, parent, recognizerSettings=None, size=100):
            QtGui.QGraphicsScene.__init__(self, parent)

            self.size = 100
            self.writing = None

            # set pen for handwriting
            self.pen = QtGui.QPen()
            self.pen.setWidth(3)

            self.strokeItemGroups = []
            self.currentStrokeItems = []

            self.setSize(size)
            if recognizerSettings:
                self.setDictionary(recognizerSettings)

        def setDictionary(self, recognizerSettings={}):
            #self.clear_strokes()

            #initialize the default dictionary and a simple recognizer
            if recognizerType == 'tomoe' \
                and 'tomoe' in recognizerSettings \
                and 'dictionary' in recognizerSettings['tomoe']:
                tomoeDict = Dict("XML",
                    filename=recognizerSettings['tomoe']['dictionary'])
                self.recognizer = Recognizer('Simple',
                    dictionary=tomoeDict)

                # will encapsulate stroke data
                if not self.writing:
                    self.writing = Writing()
            elif recognizerType == 'tegaki':
                recognizers = Recognizer.get_available_recognizers()

                if not recognizers:
                    raise Exception('No recognizer available')

                if 'tegaki' in recognizerSettings \
                    and 'recognizer' in recognizerSettings['tegaki']:
                    engine = recognizerSettings['tegaki']['recognizer']
                    if engine not in recognizers:
                        raise Exception('recognizer not available')
                else:
                    engine = recognizers.keys()[0]

                recognizer_klass = recognizers[engine]
                self.recognizer = recognizer_klass()

                if 'tegaki' in recognizerSettings \
                    and 'model' in recognizerSettings['tegaki']:
                    model = recognizerSettings['tegaki']['model']
                    if model not in recognizer_klass.get_available_models():
                        raise Exception('Model not available')
                else:
                    model = recognizer_klass.get_available_models().keys()[0]

                self.recognizer.set_model(model)

                # will encapsulate stroke data
                if not self.writing:
                    self.writing = Writing()
            else:
                self.writing = None

        def enabled(self):
            #return True
            return self.writing != None # TODO bug ?

        def setSize(self, size):
            for group in self.strokeItemGroups:
                for item in group:
                    self.removeItem(item)

            self.clear()

            self.setSceneRect(0, 0, size, size)

            # draw character grid
            self.setBackgroundBrush(QtCore.Qt.lightGray)
            self.addRect(-1, -1, size+2, size+2,
                QtCore.Qt.white, QtCore.Qt.white).setZValue(-1)
            self.addRect(0.1 * size, 0.1 * size, 0.8 * size, 0.8 * size)
            self.addLine(0.5 * size, 0.1 * size, 0.5 * size, 0.9 * size,
                QtGui.QPen(QtCore.Qt.DashLine))
            self.addLine(0.1 * size, 0.5 * size, 0.9 * size, 0.5 * size,
                QtGui.QPen(QtCore.Qt.DashLine))

            # recalculate drawn strokes
            scaleFactor = 1.0 * size / self.size
            for group in self.strokeItemGroups:
                for item in group:
                    self.addItem(item)
                    line = item.line()
                    line.setLine(line.x1() * scaleFactor,
                        line.y1() * scaleFactor, line.x2() * scaleFactor,
                        line.y2() * scaleFactor)
                    item.setLine(line)

            self.size = size

        def clear_strokes(self):
            """Removes all strokes and clears the drawing area."""
            if self.strokeItemGroups:
                for group in self.strokeItemGroups:
                    for item in group:
                        self.removeItem(item)

                self.strokeItemGroups = []
                if self.writing:
                    self.writing.clear()

        def remove_last_stroke(self):
            """Removes the latest stroke."""
            if self.strokeItemGroups:
                for item in self.strokeItemGroups.pop():
                    self.removeItem(item)

                if self.writing:
                    self.writing.remove_last_stroke()

        def strokeCount(self):
            return self.writing.get_n_strokes()

        def doSearch(self, maxResults=10):
            """Searches for the current stroke input and returns the results."""
            if self.writing and self.writing.get_n_strokes() > 0:
                if recognizerType == 'tomoe':
                    res = self.recognizer.search(self.writing)

                    if maxResults != None:
                        res = res[:min(maxResults, len(res))]

                    return [(r.get_char().get_utf8().decode('utf8'),
                        r.get_score()) for r in res]

                elif recognizerType == 'tegaki':
                    return [(c.decode('utf8'), score) for c, score \
                        in self.recognizer.recognize(self.writing, maxResults)]
            else:
                return []

        def mouseReleaseEvent(self, mouseEvent):
            if mouseEvent.button() & QtCore.Qt.LeftButton:
                # left button released

                #pos = mouseEvent.scenePos()
                #self.keepBounds(pos)
                #self.writing.line_to(pos.x() * 1000 / self.size,
                    #pos.y() * 1000 / self.size)

                self.strokeItemGroups.append(self.currentStrokeItems)
                self.currentStrokeItems = []
                self.emit(QtCore.SIGNAL("strokeAdded()"))

        def mousePressEvent(self, mouseEvent):
            if mouseEvent.button() & QtCore.Qt.LeftButton:
                # left button pressed
                pos = mouseEvent.scenePos()
                self.keepBounds(pos)

                self.writing.move_to(int(pos.x() * 1000 / self.size),
                    int(pos.y() * 1000 / self.size))

        def mouseMoveEvent(self, mouseEvent):
            if mouseEvent.buttons() & QtCore.Qt.LeftButton:
                # mouse is moved with the left button hold down
                lastPos = mouseEvent.lastScenePos()
                self.keepBounds(lastPos)
                pos = mouseEvent.scenePos()
                self.keepBounds(pos)
                self.currentStrokeItems.append(
                    self.addLine(QtCore.QLineF(lastPos, pos), self.pen))

                # tomoe seems to use a 1000x1000 pixel grid
                self.writing.line_to(int(pos.x() * 1000 / self.size),
                    int(pos.y() * 1000 / self.size))

        def keepBounds(self, point):
            """Keep the coordinates inside the scene rectangle."""
            point.setX(min(max(0, point.x()), self.size))
            point.setY(min(max(0, point.y()), self.size))
示例#14
0
 def __init__(self):
     Recognizer.__init__(self)
     self._recognizer = zinnia.Recognizer()
示例#15
0
 def __init__(self):
     Recognizer.__init__(self)
     self._recognizer = zinnia.Recognizer()
示例#16
0
        def __init__(self):
            Recognizer.__init__(self)
            _WagomuBase.__init__(self)

            self._recognizer = wagomu.Recognizer()
示例#17
0
        def __init__(self):
            Recognizer.__init__(self)
            _WagomuBase.__init__(self)

            self._recognizer = wagomu.Recognizer()
示例#18
0
 def __init__(self):
     Recognizer.__init__(self)
     self._recognizer = zinnia.Recognizer()
     print "Hangul initialized!"