-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.py
39 lines (27 loc) · 987 Bytes
/
interfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Common interfaces for the MRZ reader components"""
import abc
from dataclasses import dataclass
from typing import Optional
@dataclass
class PreProcessors:
"""A configuration of preprocessors"""
grayscale: Optional[bool] = None
threshold: Optional[int] = None
variable_threshold: Optional[bool] = None
@dataclass
class PostProcessors:
"""A configuration of postprocessors"""
character_height: Optional[bool] = None
mrz_fields: Optional[bool] = None
line_lengths: Optional[bool] = None
@dataclass
class PostProcessorMetadata:
"""Metadata generated by the engine for the postprocessors"""
box_heights: Optional[list[float]] = None
class Engine(abc.ABC):
"""The engines capable of doing the main OCR task"""
@abc.abstractmethod
def get_mrz_text(
self, image, verbose=False
) -> Optional[tuple[str, PostProcessorMetadata]]:
"""Read the MRZ text from an image, and generate metadata for postprocessing"""