Last modified: February 13, 2012
Contents
In module gamera.toolkits.ocr.classes
The Page object offers the page segmentation functionality by providing a segment method. See its documentation for more information on how to overwrite specific steps of the segmentation process.
After the call of segment, the segmentation results are stored in the following attributes of Page:
- textlines
- List of Textline objects representing all text lines
- img
- The image to which Ccs in the textlines refer.
The only required argument in the constructor is the image that is to be segmented. Note that the constructor does not do the segmentation; for this, you must call the segment method.
Signature:
init (image, glyphs=None, classify_ccs=None)
with
- image:
- The image to be segmented.
- glyphs:
- An optional list of connected components representing the characters in the image. In general, this is not needed, but it can be useful for bottom up methods starting from already detected characters (e.g. by Gamera's classification based character grouping.
- classify_ccs:
- A callable class with the same interface as ClassifyCCs. If given, it will be called during the segmentation process, right after the splitting of lines to characters.
Segments Page.img and stores the result in Page.textlines. This method has no arguments.
It calls the following methods in the given order:
- page_to_lines for splitting the page into segments representing text lines
- order_lines for sorting the lines into reading order
- lines_to_chars for splitting all lines into characters
- Page.classify_ccs when it is set, i.e., has been passed to the constructor (default is that it is not set)
- chars_to_words for grouping the characters to words
By overwriting one (or several) of the above functions, you can replace specific steps of the segmentation process with custom algorithms.
Splits the image into segments representing text lines. This method has no arguments.
The current implementation simply calls the bbox_merging plugin from the Gamera core with Ey=0, such that the page is not split into paragraphs, but into lines.
The segmentation result is stored in the variable Page.ccs_lines, which is a list of the data type Cc, i.e., with each segment (line) represented by a different label in the image. This is the interface used by all page segmentation plugins in the Gamera core.
Note
When you overwrite this method, make sure that write the segmentation result to self.ccs_lines. This member variable will then be further processed by lines_to_chars.
Sorts the segments in Page.ccs_lines into reading order. This method has no arguments.
The current implementation uses the plugin textline_reading_order from the Gamera core.
Splits text lines into characters. Signature:
lines_to_chars (lines=None)
lines must be a list of Cc data types, each of them representing a text line. When not given (default), Page.ccs_lines is used instead. The current implementation calls get_line_glyphs as defined in the module ocr_toolkit.
The result is stored in Page.textlines; the characters are stored for each textline in Textline.glyphs.
Groups the characters in each Textline from Page.textlines to words and stores the result for each Textline in the property Textline.words.
This method has an optional but generally useless argument for the list of textlines. It is therefore usually called without arguments.
The current implementation calls chars_make_words as defined in the module ocr_toolkit.
Returns an RGB image with all segmented text lines marked by hollow rects. Makes only sense after page_to_lines (or segment) has been called.
Returns an RGB image with all segmented/grouped characters marked by hollow rects. Makes only sense after lines_to_chars (or segment) has been called.
Returns an RGB image with all grouped words marked by hollow rects. Makes only sense after chars_to_words (or segment) has been called..