Base¶
Base class for OCR extractors.
Defines the abstract interface that all OCR extractors must implement.
BaseOCRExtractor
¶
Bases: ABC
Abstract base class for OCR extractors.
All OCR extraction models must inherit from this class and implement the required methods.
Example
extract
abstractmethod
¶
Run OCR extraction on an image.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
Input image as: - PIL.Image.Image: PIL image object - np.ndarray: Numpy array (HWC format, RGB) - str or Path: Path to image file
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OCROutput
|
OCROutput containing detected text blocks with bounding boxes |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If image format is not supported |
RuntimeError
|
If OCR engine is not initialized or extraction fails |
Source code in omnidocs/tasks/ocr_extraction/base.py
batch_extract
¶
batch_extract(
images: List[Union[Image, ndarray, str, Path]],
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[OCROutput]
Run OCR extraction on multiple images.
Default implementation loops over extract(). Subclasses can override for optimized batching.
| PARAMETER | DESCRIPTION |
|---|---|
images
|
List of images in any supported format
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[OCROutput]
|
List of OCROutput in same order as input |
Examples:
Source code in omnidocs/tasks/ocr_extraction/base.py
extract_document
¶
extract_document(
document: Document,
progress_callback: Optional[
Callable[[int, int], None]
] = None,
) -> List[OCROutput]
Run OCR extraction on all pages of a document.
| PARAMETER | DESCRIPTION |
|---|---|
document
|
Document instance
TYPE:
|
progress_callback
|
Optional function(current, total) for progress
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[OCROutput]
|
List of OCROutput, one per page |
Examples: