page_elements2.py
def save_margin_content(self, tree, content_box):
        '''Look at margin content and try to OCR it. Save results in a pickle
        file of a dictionary object:
        d = {'left':['margin info 1', ...], 'right':['right margin info 1', etc]}
        
        Margin content is tricky since letters are often not defined as well
        as the main page content. The current OCR implementation also stumbles
        on text with very few characters. Page numbers don't do well for some
        reason...
        '''
        
        import cPickle as pickle
        import os
        content_box_right_edge = tree[content_box]['b'][0] + tree[content_box]['b'][2]
        inset = 20

        right_content = []
        left_content = []
        for brnch in tree:
            if brnch != content_box:
                outer_box = brnch

                if tree[outer_box]['num_chars'] != 0:
                    bx = tree[outer_box]['b']
                    arr = self.img_arr[bx[1]+inset:bx[1]+bx[3]-inset, bx[0]+inset:bx[0]+bx[2]-inset]

                    text = ''
                    if bx[0] > content_box_right_edge:
                        arr = rotate(arr, -90, cval=1)
                        text = construct_page(rec_main(arr, line_break_method='line_cut', page_type='book', page_info={'flname': 'margin content'}))
                        if text:
                            right_content.append(text)
                    else:
                        arr = rotate(arr, 90, cval=1)
                        text = construct_page(rec_main(arr, line_break_method='line_cut', page_type='book', page_info={'flname': 'margin content'}))
                        if text:
                            left_content.append(text)
        pklname = os.path.join(os.path.dirname(self.flpath), os.path.basename(self.flpath)[:-4]+'_margin_content.pkl')
        pickle.dump({'right':right_content, 'left':left_content}, open(pklname, 'wb'))
Look at margin content and try to OCR it. Save results in a pickle
        file of a dictionary object:
        d = {'left':['margin info 1', ...], 'right':['right margin info 1', etc]}
        
        Margin content is tricky since letters are often not defined as well
        as the main page content. The current OCR implementation also stumbles
        on text with very few characters. Page numbers don't do well for some
        reason...
        
Look at margin content and try to OCR it.

Margin content is tricky since letters are often not defined as well
as the main page content. The current OCR implementation also stumbles
on text with very few characters. Page numbers don't do well for some
reason
Look at margin content and try to OCR it . Margin content is tricky since letters are often not defined as well as the main page content . The current OCR implementation also stumbles on text with very few characters . Page numbers don ' t do well for some reason
def save_margin_content(self, tree, content_box):
        import cPickle as pickle
        import os
        content_box_right_edge = tree[content_box]['b'][0] + tree[content_box]['b'][2]
        inset = 20
        right_content = []
        left_content = []
        for brnch in tree:
            if brnch != content_box:
                outer_box = brnch
                if tree[outer_box]['num_chars'] != 0:
                    bx = tree[outer_box]['b']
                    arr = self.img_arr[bx[1]+inset:bx[1]+bx[3]-inset, bx[0]+inset:bx[0]+bx[2]-inset]
                    text = ''
                    if bx[0] > content_box_right_edge:
                        arr = rotate(arr, -90, cval=1)
                        text = construct_page(rec_main(arr, line_break_method='line_cut', page_type='book', page_info={'flname': 'margin content'}))
                        if text:
                            right_content.append(text)
                    else:
                        arr = rotate(arr, 90, cval=1)
                        text = construct_page(rec_main(arr, line_break_method='line_cut', page_type='book', page_info={'flname': 'margin content'}))
                        if text:
                            left_content.append(text)
        pklname = os.path.join(os.path.dirname(self.flpath), os.path.basename(self.flpath)[:-4]+'_margin_content.pkl')
        pickle.dump({'right':right_content, 'left':left_content}, open(pklname, 'wb'))
def save_margin_content ( self , tree , content_box ) : import cPickle as pickle import os content_box_right_edge = tree [ content_box ] [ 'b' ] [ 0 ] + tree [ content_box ] [ 'b' ] [ 2 ] inset = 20 right_content = [ ] left_content = [ ] for brnch in tree : if brnch != content_box : outer_box = brnch if tree [ outer_box ] [ 'num_chars' ] != 0 : bx = tree [ outer_box ] [ 'b' ] arr = self . img_arr [ bx [ 1 ] + inset : bx [ 1 ] + bx [ 3 ] - inset , bx [ 0 ] + inset : bx [ 0 ] + bx [ 2 ] - inset ] text = '' if bx [ 0 ] > content_box_right_edge : arr = rotate ( arr , - 90 , cval = 1 ) text = construct_page ( rec_main ( arr , line_break_method = 'line_cut' , page_type = 'book' , page_info = { 'flname' : 'margin content' } ) ) if text : right_content . append ( text ) else : arr = rotate ( arr , 90 , cval = 1 ) text = construct_page ( rec_main ( arr , line_break_method = 'line_cut' , page_type = 'book' , page_info = { 'flname' : 'margin content' } ) ) if text : left_content . append ( text ) pklname = os . path . join ( os . path . dirname ( self . flpath ) , os . path . basename ( self . flpath ) [ : - 4 ] + '_margin_content.pkl' ) pickle . dump ( { 'right' : right_content , 'left' : left_content } , open ( pklname , 'wb' ) )
Look at margin content and try to OCR it.
Look at margin content and try to OCR it .
'''Look at margin content and try to OCR it. Save results in a pickle
        file of a dictionary object:
        d = {'left':['margin info 1', ...], 'right':['right margin info 1', etc]}
        
        Margin content is tricky since letters are often not defined as well
        as the main page content. The current OCR implementation also stumbles
        on text with very few characters. Page numbers don't do well for some
        reason...
        '''
self
tree
content_box