ocrd_cis/ocropy/recognize.py
def process(self):
        """Recognize lines / words / glyphs of the workspace.

        Open and deserialise each PAGE input file and its respective image,
        then iterate over the element hierarchy down to the requested
        ``textequiv_level``. If any layout annotation below the line level
        already exists, then remove it (regardless of ``textequiv_level``).

        Set up Ocropy to recognise each text line (via coordinates into
        the higher-level image, or from the alternative image; the image
        must have been binarised/grayscale-normalised, deskewed and dewarped
        already). Rescale and pad the image, then recognize.

        Create new elements below the line level, if necessary.
        Put text results and confidence values into new TextEquiv at
        ``textequiv_level``, and make the higher levels consistent with that
        up to the line level (by concatenation joined by whitespace).

        If a TextLine contained any previous text annotation, then compare
        that with the new result by aligning characters and computing the
        Levenshtein distance. Aggregate these scores for each file and print
        the line-wise and the total character error rates (CER).

        Produce a new output file by serialising the resulting hierarchy.
        """
        assert_file_grp_cardinality(self.input_file_grp, 1)
        assert_file_grp_cardinality(self.output_file_grp, 1)
        maxlevel = self.parameter['textequiv_level']

        # self.logger.info("Using model %s in %s for recognition", model)
        for (n, input_file) in enumerate(self.input_files):
            self.logger.info("INPUT FILE %i / %s", n, input_file.pageId or input_file.ID)
            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)

            self.logger.info("Recognizing text in page '%s'", page_id)
            # region, line, word, or glyph level:
            regions = page.get_AllRegions(classes=['Text'])
            if not regions:
                self.logger.warning("Page '%s' contains no text regions", page_id)
            self.process_regions(regions, maxlevel, page_image, page_coords)

            # update METS (add the PAGE file):
            file_id = make_file_id(input_file.ID, self.output_file_grp)
            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))
            self.logger.info('created file ID: %s, file_grp: %s, path: %s',
                             file_id, self.output_file_grp, out.local_filename)
Recognize lines / words / glyphs of the workspace.

        Open and deserialise each PAGE input file and its respective image,
        then iterate over the element hierarchy down to the requested
        ``textequiv_level``. If any layout annotation below the line level
        already exists, then remove it (regardless of ``textequiv_level``).

        Set up Ocropy to recognise each text line (via coordinates into
        the higher-level image, or from the alternative image; the image
        must have been binarised/grayscale-normalised, deskewed and dewarped
        already). Rescale and pad the image, then recognize.

        Create new elements below the line level, if necessary.
        Put text results and confidence values into new TextEquiv at
        ``textequiv_level``, and make the higher levels consistent with that
        up to the line level (by concatenation joined by whitespace).

        If a TextLine contained any previous text annotation, then compare
        that with the new result by aligning characters and computing the
        Levenshtein distance. Aggregate these scores for each file and print
        the line-wise and the total character error rates (CER).

        Produce a new output file by serialising the resulting hierarchy.
        
Recognize lines / words / glyphs of the workspace.
Open and deserialise each PAGE input file and its respective image,
then iterate over the element hierarchy down to the requested
``textequiv_level``. If any layout annotation below the line level
already exists, then remove it (regardless of ``textequiv_level``).

Set up Ocropy to recognise each text line (via coordinates into
the higher-level image, or from the alternative image; the image
must have been binarised/grayscale-normalised, deskewed and dewarped
already). Rescale and pad the image, then recognize.

Create new elements below the line level, if necessary.
Put text results and confidence values into new TextEquiv at
``textequiv_level``, and make the higher levels consistent with that
up to the line level (by concatenation joined by whitespace).

If a TextLine contained any previous text annotation, then compare
that with the new result by aligning characters and computing the
Levenshtein distance. Aggregate these scores for each file and print
the line-wise and the total character error rates (CER).

Produce a new output file by serialising the resulting hierarchy.
Recognize lines / words / glyphs of the workspace . Open and deserialise each PAGE input file and its respective image then iterate over the element hierarchy down to the requested ` ` textequiv_level ` ` . If any layout annotation below the line level already exists then remove it ( regardless of ` ` textequiv_level ` ` ) . Set up Ocropy to recognise each text line ( via coordinates into the higher - level image or from the alternative image ; the image must have been binarised / grayscale - normalised deskewed and dewarped already ) . Rescale and pad the image then recognize . Create new elements below the line level if necessary . Put text results and confidence values into new TextEquiv at ` ` textequiv_level ` ` and make the higher levels consistent with that up to the line level ( by concatenation joined by whitespace ) . If a TextLine contained any previous text annotation then compare that with the new result by aligning characters and computing the Levenshtein distance . Aggregate these scores for each file and print the line - wise and the total character error rates ( CER ) . Produce a new output file by serialising the resulting hierarchy .
def process(self):
        assert_file_grp_cardinality(self.input_file_grp, 1)
        assert_file_grp_cardinality(self.output_file_grp, 1)
        maxlevel = self.parameter['textequiv_level']
        for (n, input_file) in enumerate(self.input_files):
            self.logger.info("INPUT FILE %i / %s", n, input_file.pageId or input_file.ID)
            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)
            self.logger.info("Recognizing text in page '%s'", page_id)
            regions = page.get_AllRegions(classes=['Text'])
            if not regions:
                self.logger.warning("Page '%s' contains no text regions", page_id)
            self.process_regions(regions, maxlevel, page_image, page_coords)
            file_id = make_file_id(input_file.ID, self.output_file_grp)
            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))
            self.logger.info('created file ID: %s, file_grp: %s, path: %s',
                             file_id, self.output_file_grp, out.local_filename)
def process ( self ) : assert_file_grp_cardinality ( self . input_file_grp , 1 ) assert_file_grp_cardinality ( self . output_file_grp , 1 ) maxlevel = self . parameter [ 'textequiv_level' ] for ( n , input_file ) in enumerate ( self . input_files ) : self . logger . info ( "INPUT FILE %i / %s" , n , input_file . pageId or input_file . ID ) 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 ) self . logger . info ( "Recognizing text in page '%s'" , page_id ) regions = page . get_AllRegions ( classes = [ 'Text' ] ) if not regions : self . logger . warning ( "Page '%s' contains no text regions" , page_id ) self . process_regions ( regions , maxlevel , page_image , page_coords ) file_id = make_file_id ( input_file . ID , self . output_file_grp ) 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 ) ) self . logger . info ( 'created file ID: %s, file_grp: %s, path: %s' , file_id , self . output_file_grp , out . local_filename )
Recognize lines / words / glyphs of the workspace.
Recognize lines / words / glyphs of the workspace .
"""Recognize lines / words / glyphs of the workspace.

        Open and deserialise each PAGE input file and its respective image,
        then iterate over the element hierarchy down to the requested
        ``textequiv_level``. If any layout annotation below the line level
        already exists, then remove it (regardless of ``textequiv_level``).

        Set up Ocropy to recognise each text line (via coordinates into
        the higher-level image, or from the alternative image; the image
        must have been binarised/grayscale-normalised, deskewed and dewarped
        already). Rescale and pad the image, then recognize.

        Create new elements below the line level, if necessary.
        Put text results and confidence values into new TextEquiv at
        ``textequiv_level``, and make the higher levels consistent with that
        up to the line level (by concatenation joined by whitespace).

        If a TextLine contained any previous text annotation, then compare
        that with the new result by aligning characters and computing the
        Levenshtein distance. Aggregate these scores for each file and print
        the line-wise and the total character error rates (CER).

        Produce a new output file by serialising the resulting hierarchy.
        """ # self.logger.info("Using model %s in %s for recognition", model) # (PageType has no id) # region, line, word, or glyph level: # update METS (add the PAGE file):
self