ocrd_cis/ocropy/deskew.py
def process(self):
        """Deskew the regions of the workspace.

        Open and deserialise PAGE input files and their respective images,
        then iterate over the element hierarchy down to the TextRegion level.

        Next, for each file, crop each region image according to the layout
        annotation (via coordinates into the higher-level image, or from the
        alternative image), and determine the threshold for binarization and
        the deskewing angle of the region (up to ``maxskew``). Annotate the
        angle in the region.

        Add the new image file to the workspace along with the output fileGrp,
        and using a file ID with suffix ``.IMG-DESKEW`` along with further
        identification of the input element.

        Produce a new output file by serialising the resulting hierarchy.
        """
        LOG = getLogger('processor.OcropyDeskew')
        level = self.parameter['level-of-operation']
        assert_file_grp_cardinality(self.input_file_grp, 1)
        assert_file_grp_cardinality(self.output_file_grp, 1)

        for (n, input_file) in enumerate(self.input_files):
            LOG.info("INPUT FILE %i / %s", n, input_file.pageId or input_file.ID)
            file_id = make_file_id(input_file, self.output_file_grp)

            pcgts = page_from_file(self.workspace.download_file(input_file))
            self.add_metadata(pcgts)
            page_id = pcgts.pcGtsId or input_file.pageId or input_file.ID # (PageType has no id)
            page = pcgts.get_Page()
                
            page_image, page_coords, _ = self.workspace.image_from_page(
                page, page_id,
                # image must not have been rotated already,
                # (we will overwrite @orientation anyway,)
                # abort if no such image can be produced:
                feature_filter='deskewed' if level == 'page' else '')
            if level == 'page':
                self._process_segment(page, page_image, page_coords,
                                      "page '%s'" % page_id, input_file.pageId,
                                      file_id)
            else:
                if level == 'table':
                    regions = page.get_TableRegion()
                else: # region
                    regions = page.get_AllRegions(classes=['Text'])
                if not regions:
                    LOG.warning('Page "%s" contains no text regions', page_id)
                for region in regions:
                    # process region:
                    region_image, region_coords = self.workspace.image_from_segment(
                        region, page_image, page_coords,
                        # image must not have been rotated already,
                        # (we will overwrite @orientation anyway,)
                        # abort if no such image can be produced:
                        feature_filter='deskewed')
                    self._process_segment(region, region_image, region_coords,
                                          "region '%s'" % region.id, input_file.pageId,
                                          file_id + '_' + region.id)

            # update METS (add the PAGE file):
            file_path = os.path.join(self.output_file_grp, file_id + '.xml')
            pcgts.set_pcGtsId(file_id)
            out = self.workspace.add_file(
                ID=file_id,
                file_grp=self.output_file_grp,
                pageId=input_file.pageId,
                local_filename=file_path,
                mimetype=MIMETYPE_PAGE,
                content=to_xml(pcgts))
            LOG.info('created file ID: %s, file_grp: %s, path: %s',
                     file_id, self.output_file_grp, out.local_filename)
Deskew the regions of the workspace.

        Open and deserialise PAGE input files and their respective images,
        then iterate over the element hierarchy down to the TextRegion level.

        Next, for each file, crop each region image according to the layout
        annotation (via coordinates into the higher-level image, or from the
        alternative image), and determine the threshold for binarization and
        the deskewing angle of the region (up to ``maxskew``). Annotate the
        angle in the region.

        Add the new image file to the workspace along with the output fileGrp,
        and using a file ID with suffix ``.IMG-DESKEW`` along with further
        identification of the input element.

        Produce a new output file by serialising the resulting hierarchy.
        
Deskew the regions of the workspace.
Open and deserialise PAGE input files and their respective images,
then iterate over the element hierarchy down to the TextRegion level.

Next, for each file, crop each region image according to the layout
annotation (via coordinates into the higher-level image, or from the
alternative image), and determine the threshold for binarization and
the deskewing angle of the region (up to ``maxskew``). Annotate the
angle in the region.

Add the new image file to the workspace along with the output fileGrp,
and using a file ID with suffix ``.IMG-DESKEW`` along with further
identification of the input element.

Produce a new output file by serialising the resulting hierarchy.
Deskew the regions of the workspace . Open and deserialise PAGE input files and their respective images then iterate over the element hierarchy down to the TextRegion level . Next for each file crop each region image according to the layout annotation ( via coordinates into the higher - level image or from the alternative image ) and determine the threshold for binarization and the deskewing angle of the region ( up to ` ` maxskew ` ` ) . Annotate the angle in the region . Add the new image file to the workspace along with the output fileGrp and using a file ID with suffix ` ` . IMG - DESKEW ` ` along with further identification of the input element . Produce a new output file by serialising the resulting hierarchy .
def process(self):
        LOG = getLogger('processor.OcropyDeskew')
        level = self.parameter['level-of-operation']
        assert_file_grp_cardinality(self.input_file_grp, 1)
        assert_file_grp_cardinality(self.output_file_grp, 1)
        for (n, input_file) in enumerate(self.input_files):
            LOG.info("INPUT FILE %i / %s", n, input_file.pageId or input_file.ID)
            file_id = make_file_id(input_file, self.output_file_grp)
            pcgts = page_from_file(self.workspace.download_file(input_file))
            self.add_metadata(pcgts)
            page_id = pcgts.pcGtsId or input_file.pageId or input_file.ID 
            page = pcgts.get_Page()
            page_image, page_coords, _ = self.workspace.image_from_page(
                page, page_id,
                feature_filter='deskewed' if level == 'page' else '')
            if level == 'page':
                self._process_segment(page, page_image, page_coords,
                                      "page '%s'" % page_id, input_file.pageId,
                                      file_id)
            else:
                if level == 'table':
                    regions = page.get_TableRegion()
                else: 
                    regions = page.get_AllRegions(classes=['Text'])
                if not regions:
                    LOG.warning('Page "%s" contains no text regions', page_id)
                for region in regions:
                    region_image, region_coords = self.workspace.image_from_segment(
                        region, page_image, page_coords,
                        feature_filter='deskewed')
                    self._process_segment(region, region_image, region_coords,
                                          "region '%s'" % region.id, input_file.pageId,
                                          file_id + '_' + region.id)
            file_path = os.path.join(self.output_file_grp, file_id + '.xml')
            pcgts.set_pcGtsId(file_id)
            out = self.workspace.add_file(
                ID=file_id,
                file_grp=self.output_file_grp,
                pageId=input_file.pageId,
                local_filename=file_path,
                mimetype=MIMETYPE_PAGE,
                content=to_xml(pcgts))
            LOG.info('created file ID: %s, file_grp: %s, path: %s',
                     file_id, self.output_file_grp, out.local_filename)
def process ( self ) : LOG = getLogger ( 'processor.OcropyDeskew' ) level = self . parameter [ 'level-of-operation' ] assert_file_grp_cardinality ( self . input_file_grp , 1 ) assert_file_grp_cardinality ( self . output_file_grp , 1 ) for ( n , input_file ) in enumerate ( self . input_files ) : LOG . info ( "INPUT FILE %i / %s" , n , input_file . pageId or input_file . ID ) file_id = make_file_id ( input_file , self . output_file_grp ) pcgts = page_from_file ( self . workspace . download_file ( input_file ) ) self . add_metadata ( pcgts ) page_id = pcgts . pcGtsId or input_file . pageId or input_file . ID page = pcgts . get_Page ( ) page_image , page_coords , _ = self . workspace . image_from_page ( page , page_id , feature_filter = 'deskewed' if level == 'page' else '' ) if level == 'page' : self . _process_segment ( page , page_image , page_coords , "page '%s'" % page_id , input_file . pageId , file_id ) else : if level == 'table' : regions = page . get_TableRegion ( ) else : regions = page . get_AllRegions ( classes = [ 'Text' ] ) if not regions : LOG . warning ( 'Page "%s" contains no text regions' , page_id ) for region in regions : region_image , region_coords = self . workspace . image_from_segment ( region , page_image , page_coords , feature_filter = 'deskewed' ) self . _process_segment ( region , region_image , region_coords , "region '%s'" % region . id , input_file . pageId , file_id + '_' + region . id ) file_path = os . path . join ( self . output_file_grp , file_id + '.xml' ) pcgts . set_pcGtsId ( file_id ) out = self . workspace . add_file ( ID = file_id , file_grp = self . output_file_grp , pageId = input_file . pageId , local_filename = file_path , mimetype = MIMETYPE_PAGE , content = to_xml ( pcgts ) ) LOG . info ( 'created file ID: %s, file_grp: %s, path: %s' , file_id , self . output_file_grp , out . local_filename )
Deskew the regions of the workspace.
Deskew the regions of the workspace .
"""Deskew the regions of the workspace.

        Open and deserialise PAGE input files and their respective images,
        then iterate over the element hierarchy down to the TextRegion level.

        Next, for each file, crop each region image according to the layout
        annotation (via coordinates into the higher-level image, or from the
        alternative image), and determine the threshold for binarization and
        the deskewing angle of the region (up to ``maxskew``). Annotate the
        angle in the region.

        Add the new image file to the workspace along with the output fileGrp,
        and using a file ID with suffix ``.IMG-DESKEW`` along with further
        identification of the input element.

        Produce a new output file by serialising the resulting hierarchy.
        """ # (PageType has no id) # image must not have been rotated already, # (we will overwrite @orientation anyway,) # abort if no such image can be produced: # region # process region: # image must not have been rotated already, # (we will overwrite @orientation anyway,) # abort if no such image can be produced: # update METS (add the PAGE file):
self