TextExtractor.py
def order_boxes(boxes):
    ''' method that orders boxes in a left-to-right, top-to-bottom
        approach. This has it's faults when it comes to memes,
        but generally is a safe-approach.
    '''
    boxes.sort(key=lambda b: b[1])
    # initially the line bottom is set to be the bottom of the first rect
    line_bottom = boxes[0][1]+boxes[0][3]-1
    line_begin_idx = 0
    for i in range(len(boxes)):
        # when a new box's top is below current line's bottom
        # it's a new line
        if boxes[i][1] > line_bottom:
            # sort the previous line by their x
            boxes[line_begin_idx:i] = sorted(boxes[line_begin_idx:i], key=lambda b: b[0])
            line_begin_idx = i
        # regardless if it's a new line or not
        # always update the line bottom
        line_bottom = max(boxes[i][1]+boxes[i][3]-1, line_bottom)
    # sort the last line
    boxes[line_begin_idx:] = sorted(boxes[line_begin_idx:], key=lambda b: b[0])
    return boxes
 method that orders boxes in a left-to-right, top-to-bottom
        approach. This has it's faults when it comes to memes,
        but generally is a safe-approach.
    
method that orders boxes in a left-to-right, top-to-bottom
approach. This has it's faults when it comes to memes,
but generally is a safe-approach.
method that orders boxes in a left - to - right top - to - bottom approach . This has it ' s faults when it comes to memes but generally is a safe - approach .
def order_boxes(boxes):
    boxes.sort(key=lambda b: b[1])
    line_bottom = boxes[0][1]+boxes[0][3]-1
    line_begin_idx = 0
    for i in range(len(boxes)):
        if boxes[i][1] > line_bottom:
            boxes[line_begin_idx:i] = sorted(boxes[line_begin_idx:i], key=lambda b: b[0])
            line_begin_idx = i
        line_bottom = max(boxes[i][1]+boxes[i][3]-1, line_bottom)
    boxes[line_begin_idx:] = sorted(boxes[line_begin_idx:], key=lambda b: b[0])
    return boxes
def order_boxes ( boxes ) : boxes . sort ( key = lambda b : b [ 1 ] ) line_bottom = boxes [ 0 ] [ 1 ] + boxes [ 0 ] [ 3 ] - 1 line_begin_idx = 0 for i in range ( len ( boxes ) ) : if boxes [ i ] [ 1 ] > line_bottom : boxes [ line_begin_idx : i ] = sorted ( boxes [ line_begin_idx : i ] , key = lambda b : b [ 0 ] ) line_begin_idx = i line_bottom = max ( boxes [ i ] [ 1 ] + boxes [ i ] [ 3 ] - 1 , line_bottom ) boxes [ line_begin_idx : ] = sorted ( boxes [ line_begin_idx : ] , key = lambda b : b [ 0 ] ) return boxes
method that orders boxes in a left-to-right, top-to-bottom
approach.
method that orders boxes in a left - to - right top - to - bottom approach .
''' method that orders boxes in a left-to-right, top-to-bottom
        approach. This has it's faults when it comes to memes,
        but generally is a safe-approach.
    ''' # initially the line bottom is set to be the bottom of the first rect # when a new box's top is below current line's bottom # it's a new line # sort the previous line by their x # regardless if it's a new line or not # always update the line bottom # sort the last line
boxes