ocrd_cis/ocropy/ocrolib/psegutils.py
def reading_order(lines,highlight=None,debug=0):
    """Given the list of lines (a list of 2D slices), computes
    the partial reading order.  The output is a binary 2D array
    such that order[i,j] is true if line i comes before line j
    in reading order."""
    order = np.zeros((len(lines),len(lines)),'B')
    def x_overlaps(u,v):
        return u[1].start<v[1].stop and u[1].stop>v[1].start
    def above(u,v):
        return u[0].start<v[0].start
    def left_of(u,v):
        return u[1].stop<v[1].start
    def separates(w,u,v):
        if w[0].stop<min(u[0].start,v[0].start): return 0
        if w[0].start>max(u[0].stop,v[0].stop): return 0
        if w[1].start<u[1].stop and w[1].stop>v[1].start: return 1
        return 0
    if highlight is not None:
        import matplotlib.pyplot as plt
        plt.clf()
        plt.title("highlight")
        plt.imshow(lines)
        plt.ginput(1,debug)
    for i,u in enumerate(lines):
        for j,v in enumerate(lines):
            if x_overlaps(u,v):
                if above(u,v):
                    order[i,j] = 1
            else:
                if [w for w in lines if separates(w,u,v)]==[]:
                    if left_of(u,v): order[i,j] = 1
            if j==highlight and order[i,j]:
                print((i, j), end=' ')
                y0,x0 = sl.center(lines[i])
                y1,x1 = sl.center(lines[j])
                plt.plot([x0,x1+200],[y0,y1])
    if highlight is not None:
        print()
        plt.ginput(1,debug)
    return order
Given the list of lines (a list of 2D slices), computes
    the partial reading order.  The output is a binary 2D array
    such that order[i,j] is true if line i comes before line j
    in reading order.
Given the list of lines (a list of 2D slices), computes
the partial reading order.  The output is a binary 2D array
such that order[i,j] is true if line i comes before line j
in reading order.
Given the list of lines ( a list of 2D slices ) computes the partial reading order . The output is a binary 2D array such that order [ i j ] is true if line i comes before line j in reading order .
def reading_order(lines,highlight=None,debug=0):
    order = np.zeros((len(lines),len(lines)),'B')
    def x_overlaps(u,v):
        return u[1].start<v[1].stop and u[1].stop>v[1].start
    def above(u,v):
        return u[0].start<v[0].start
    def left_of(u,v):
        return u[1].stop<v[1].start
    def separates(w,u,v):
        if w[0].stop<min(u[0].start,v[0].start): return 0
        if w[0].start>max(u[0].stop,v[0].stop): return 0
        if w[1].start<u[1].stop and w[1].stop>v[1].start: return 1
        return 0
    if highlight is not None:
        import matplotlib.pyplot as plt
        plt.clf()
        plt.title("highlight")
        plt.imshow(lines)
        plt.ginput(1,debug)
    for i,u in enumerate(lines):
        for j,v in enumerate(lines):
            if x_overlaps(u,v):
                if above(u,v):
                    order[i,j] = 1
            else:
                if [w for w in lines if separates(w,u,v)]==[]:
                    if left_of(u,v): order[i,j] = 1
            if j==highlight and order[i,j]:
                print((i, j), end=' ')
                y0,x0 = sl.center(lines[i])
                y1,x1 = sl.center(lines[j])
                plt.plot([x0,x1+200],[y0,y1])
    if highlight is not None:
        print()
        plt.ginput(1,debug)
    return order
def reading_order ( lines , highlight = None , debug = 0 ) : order = np . zeros ( ( len ( lines ) , len ( lines ) ) , 'B' ) def x_overlaps ( u , v ) : return u [ 1 ] . start < v [ 1 ] . stop and u [ 1 ] . stop > v [ 1 ] . start def above ( u , v ) : return u [ 0 ] . start < v [ 0 ] . start def left_of ( u , v ) : return u [ 1 ] . stop < v [ 1 ] . start def separates ( w , u , v ) : if w [ 0 ] . stop < min ( u [ 0 ] . start , v [ 0 ] . start ) : return 0 if w [ 0 ] . start > max ( u [ 0 ] . stop , v [ 0 ] . stop ) : return 0 if w [ 1 ] . start < u [ 1 ] . stop and w [ 1 ] . stop > v [ 1 ] . start : return 1 return 0 if highlight is not None : import matplotlib . pyplot as plt plt . clf ( ) plt . title ( "highlight" ) plt . imshow ( lines ) plt . ginput ( 1 , debug ) for i , u in enumerate ( lines ) : for j , v in enumerate ( lines ) : if x_overlaps ( u , v ) : if above ( u , v ) : order [ i , j ] = 1 else : if [ w for w in lines if separates ( w , u , v ) ] == [ ] : if left_of ( u , v ) : order [ i , j ] = 1 if j == highlight and order [ i , j ] : print ( ( i , j ) , end = ' ' ) y0 , x0 = sl . center ( lines [ i ] ) y1 , x1 = sl . center ( lines [ j ] ) plt . plot ( [ x0 , x1 + 200 ] , [ y0 , y1 ] ) if highlight is not None : print ( ) plt . ginput ( 1 , debug ) return order
Given the list of lines (a list of 2D slices), computes
the partial reading order.
Given the list of lines ( a list of 2D slices ) computes the partial reading order .
"""Given the list of lines (a list of 2D slices), computes
    the partial reading order.  The output is a binary 2D array
    such that order[i,j] is true if line i comes before line j
    in reading order."""
lines
highlight
debug