コード例 #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'))
コード例 #3
0
ファイル: iuutils.py プロジェクト: UIKit0/iulib
def narray2numpy(na,type='B'):
    """Convert an narray image to a numpy image. Flips from mathematical
    coordinates to raster coordinates.  When converting integer to float
    types, multiplies with 255.0, and when converting integer to float
    types divides by 255.0"""
    checkna(na)
    if type is None: type = ctype(na)
    if isfp(na) and not isfp(type):
        page = iulib.numpy(na,'f')
        page = array(255.0*page,dtype=type)
    elif not isfp(na) and isfp(type):
        page = iulib.numpy(na,type=type)
        page /= 255.0
    else:
        page = iulib.numpy(na,type=type)
    return page.transpose([1,0]+range(2,page.ndim))[::-1,...]
コード例 #4
0
def narray2lseg(na):
    """Convert an narray to a line segmentation."""
    checkna(na)
    pseg = iulib.numpy(na, type='i')
    pseg = transpose(pseg, [1, 0])
    pseg = pseg[::-1, ...]
    return pseg
コード例 #5
0
ファイル: iuutils.py プロジェクト: UIKit0/iulib
def narray2lseg(na):
    """Convert an narray to a line segmentation."""
    checkna(na)
    pseg = iulib.numpy(na,type='i')
    pseg = transpose(pseg,[1,0])
    pseg = pseg[::-1,...]
    return pseg
コード例 #6
0
def narray2numpy(na, type='B'):
    """Convert an narray image to a numpy image. Flips from mathematical
    coordinates to raster coordinates.  When converting integer to float
    types, multiplies with 255.0, and when converting integer to float
    types divides by 255.0"""
    checkna(na)
    if type is None: type = ctype(na)
    if isfp(na) and not isfp(type):
        page = iulib.numpy(na, 'f')
        page = array(255.0 * page, dtype=type)
    elif not isfp(na) and isfp(type):
        page = iulib.numpy(na, type=type)
        page /= 255.0
    else:
        page = iulib.numpy(na, type=type)
    return page.transpose([1, 0] + range(2, page.ndim))[::-1, ...]
コード例 #7
0
ファイル: iuutils.py プロジェクト: UIKit0/iulib
def narray2pseg(na):
    """Convert an narray to a page segmentation (rank 3, RGB)."""
    checkna(na)
    pseg = iulib.numpy(na,type='i')
    pseg = array([pseg>>16,pseg>>8,pseg],'B')
    pseg = transpose(pseg,[2,1,0])
    pseg = pseg[::-1,...]
    return pseg
コード例 #8
0
def narray2pseg(na):
    """Convert an narray to a page segmentation (rank 3, RGB)."""
    checkna(na)
    pseg = iulib.numpy(na, type='i')
    pseg = array([pseg >> 16, pseg >> 8, pseg], 'B')
    pseg = transpose(pseg, [2, 1, 0])
    pseg = pseg[::-1, ...]
    return pseg
コード例 #9
0
def show_segmentation(rseg):
    """Shows a line or page segmentation using Matplotlib's imshow.
    The argument should be an narray."""
    temp = iulib.numpy(rseg, type='B')
    temp[temp == 255] = 0
    temp = transpose(temp)[::-1, :]
    temp2 = 1 + (temp % 10)
    temp2[temp == 0] = 0
    temp = temp2
    print temp.shape, temp.dtype
    temp = temp / float(amax(temp))
    imshow(temp, cmap=cm.spectral)
コード例 #10
0
def N(image):
    """Convert an iulib array to a numpy image."""
    return iulib.numpy(image)
コード例 #11
0
ファイル: iuutils.py プロジェクト: UIKit0/iulib
def narray2vector(na,type='f'):
    """Convert an narray vector to numpy.  If ndim>1, it converts to
    raster coordinates.  This is used with classifiers."""
    a = iulib.numpy(na)
    if a.ndim>1: return a.transpose([1,0]+range(2,a.ndim))[::-1,...]
    else: return a
コード例 #12
0
 def numpy(self):
     """Convert an narray to a numpy array."""
     return iulib.numpy(self)
コード例 #13
0
def narray2vector(na, type='f'):
    """Convert an narray vector to numpy.  If ndim>1, it converts to
    raster coordinates.  This is used with classifiers."""
    a = iulib.numpy(na)
    if a.ndim > 1: return a.transpose([1, 0] + range(2, a.ndim))[::-1, ...]
    else: return a
コード例 #14
0
def as_numpyI(image, dtype=dtype):
    if type(image) == numpy.ndarray: return image
    image = iulib.numpy(image, type=dtype)
    image = image.transpose([1, 0] + range(2, image.ndim))
    return image[::-1, ...]
コード例 #15
0
def N(image):
    """Convert an narray to a numpy array."""
    return iulib.numpy(image)
コード例 #16
0
def as_numpy(image, flip=0, dtype='f'):
    if type(image) == numpy.ndarray: return image
    if flip and image.rank() > 1: return as_numpyI(image, dtype=dtype)
    return iulib.numpy(image, type=dtype)