Пример #1
0
 def getTransitions(self, frm):
     tos = iulib.intarray()
     symbols = iulib.intarray()
     costs = iulib.floatarray()
     inputs = iulib.intarray()
     self.comp.getTransitions(tos, symbols, costs, inputs, frm)
     return (iulib.numpy(tos, 'i'), iulib.numpy(symbols, 'i'),
             iulib.numpy(costs), iulib.numpy(inputs, 'i'))
Пример #2
0
def beam_search(lattice, lmodel, beam):
    """Perform a beam search through the lattice and language model, given the
    beam size.  Returns (v1,v2,input_symbols,output_symbols,costs)."""
    v1 = iulib.intarray()
    v2 = iulib.intarray()
    ins = iulib.intarray()
    outs = iulib.intarray()
    costs = iulib.floatarray()
    ocrofstll.beam_search(v1, v2, ins, outs, costs, native_fst(lattice),
                          native_fst(lmodel), beam)
    return (iulib.numpy(v1, 'i'), iulib.numpy(v2, 'i'), iulib.numpy(ins, 'i'),
            iulib.numpy(outs, 'i'), iulib.numpy(costs, 'f'))
def recognize_and_align(image,linerec,lmodel,beam=1000,nocseg=0):
    """Perform line recognition with the given line recognizer and
    language model.  Outputs an object containing the result (as a
    Python string), the costs, the rseg, the cseg, the lattice and the
    total cost.  The recognition lattice needs to have rseg's segment
    numbers as inputs (pairs of 16 bit numbers); SimpleGrouper
    produces such lattices.  cseg==None means that the connected
    component renumbering failed for some reason."""

    # run the recognizer
    lattice = ocropus.make_OcroFST()
    rseg = iulib.intarray()
    linerec.recognizeLineSeg(lattice,rseg,image)

    # perform the beam search through the lattice and the model
    v1 = iulib.intarray()
    v2 = iulib.intarray()
    ins = iulib.intarray()
    outs = iulib.intarray()
    costs = iulib.floatarray()
    ocropus.beam_search(v1,v2,ins,outs,costs,lattice,lmodel,beam)

    # do the conversions
    # print "OUTS",[outs.at(i) for i in range(outs.length())]
    result = intarray_as_string(outs,skip0=1)
    # print "RSLT",result

    # compute the cseg
    if not nocseg:
        rmap = rseg_map(ins)
        cseg = None
        if len(rmap)>1:
            cseg = iulib.intarray()
            cseg.copy(rseg)
            try:
                for i in range(cseg.length()):
                    cseg.put1d(i,int(rmap[rseg.at1d(i)]))
            except IndexError:
                raise Exception("renumbering failed")
    else:
        cseg = None

    # return everything we computed
    return Record(image=image,
                  output=result,
                  raw=outs,
                  costs=costs,
                  rseg=rseg,
                  cseg=cseg,
                  lattice=lattice,
                  cost=iulib.sum(costs))
Пример #4
0
#fst1.addTransition(s2, s3, 1002, 10.0,1002)
fst1.addTransition(s2, s3, 14, 20.0, 14)

a0 = fst2.newState()
a1 = fst2.newState()
a2= fst2.newState()
a3 = fst2.newState()
a4 = fst2.newState()
a5 = fst2.newState()
a6 = fst2.newState()
#O=15, t=20  c=3 R=18
fst2.setAccept(a4);
fst2.setAccept(a5);
fst2.setAccept(a6);
fst2.addTransition(a0, a1, 3, 23.0, 3);#c
fst2.addTransition(a1, a3, 15, 1.0, 15);#O
fst2.addTransition(a1, a2, 1, 20.0, 1);#a
fst2.addTransition(a2, a4, 20, 40.0, 20);#T
fst2.addTransition(a2, a5, 18, 18.0, 18);#R
fst2.addTransition(a3, a6, 23, 13.0, 23);#W

s = iulib.ustrg()
v1 = iulib.intarray()
v2 = iulib.intarray()
ins = iulib.intarray()
outs = iulib.intarray()
costs = iulib.floatarray()
n=1000
ocrofstll.beam_search(v1,v2,ins,outs,costs,fst1,fst2,n)

Пример #5
0
    def __init__(self,kind="mappedmlp",r=30,flip=1):
        self.r = r
        self.init(kind)
        self.v = iulib.floatarray()
	self.flip = flip
Пример #6
0
 def of(self,image):
     """Assign a numpy array to this narray; returns self.
     Use like floatarray().F(numpy_array)."""
     a = iulib.floatarray()
     iulib.narray_of_numpy(self,image)
     return self
Пример #7
0
def FI(image):
    """Convert a numpy array to an iulib floatarray, accounting
    for different coordinate conventions."""
    a = iulib.floatarray()
    iulib.narray_of_numpy(a, transpose(image[::-1, ...]))
    return a
Пример #8
0
def F(image):
    """Convert a numpy array to an iulib floatarray."""
    a = iulib.floatarray()
    iulib.narray_of_numpy(a, image)
    return a