Pipeline

The main high-level interface for OCR processing.

class manuscript._pipeline.Pipeline(detector=<object object>, layout=<object object>, recognizer=<object object>, corrector=None, layout_after='detector')[source]

Bases: object

High-level OCR pipeline with configurable stage ordering.

Default pipeline: detector -> layout -> recognizer. corrector is optional and disabled by default.

Attributes:
last_correction_page
last_detection_page
last_layout_page
last_recognition_page
Parameters:
  • detector (DetectorProtocol)

  • layout (LayoutProtocol | None)

  • recognizer (RecognizerProtocol | None)

  • corrector (CorrectorProtocol | None)

  • layout_after (str)

Methods

get_text(page)

Extract plain text from Page object.

predict(image[, vis, profile])

Run pipeline on a single image.

__init__(detector=<object object>, layout=<object object>, recognizer=<object object>, corrector=None, layout_after='detector')[source]

Initialize OCR pipeline.

Parameters:
  • detector (object, optional) – Detector instance with predict(image) -> Page. If omitted, default YOLO(weights="yolo26x_obb_text_g1") is used. Detector cannot be disabled.

  • layout (object or None, optional) – Layout model instance with predict(page, image=None) -> Page. If omitted, default SimpleSorting() is used. Pass None to disable layout stage.

  • recognizer (object or None, optional) – Recognizer instance with predict(page, image=None, ...) -> Page. If omitted, default TRBA(weights="trba_lite_g2") is used. Pass None to disable recognition stage.

  • corrector (object or None, optional) – Corrector instance with predict(page, image=None) -> Page. Default is None (disabled).

  • layout_after ({"detector", "recognizer", "corrector"}, optional) – Slot where layout stage is executed. Default is "detector".

predict(image, vis=False, profile=False)[source]

Run pipeline on a single image.

Parameters:
  • image (str, Path, numpy.ndarray, or PIL.Image) – Input image.

  • vis (bool, optional) – If True, returns visualization image together with result.

  • profile (bool, optional) – If True, prints timing per stage.

Return type:

Union[Dict[str, Page], tuple]

get_text(page)[source]

Extract plain text from Page object.

Return type:

str

Parameters:

page (Page)

property last_detection_page: Page | None
property last_layout_page: Page | None
property last_recognition_page: Page | None
property last_correction_page: Page | None