-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengines.py
66 lines (47 loc) · 1.98 KB
/
engines.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
The engines capable of doing the main OCR task
"""
from typing import TypedDict, Optional
from passport_mrz_reader.common.interfaces import PostProcessorMetadata, Engine
from passport_mrz_reader.pure_tesseract import tesseract_predict
from passport_mrz_reader.easy_ocr import easy_ocr_predict
from passport_mrz_reader.deep_learning import tensor_flow_predictor
class TesseractOptions(TypedDict):
"""Options for the Tesseract engine"""
class Tesseract(Engine):
"""OCR engine using Tesseract"""
def __init__(self, options: TesseractOptions):
self.options = options
def get_mrz_text(
self, original_image, preprocessed_image, verbose=False
) -> Optional[tuple[str, PostProcessorMetadata]]:
"""Get the raw MRZ text using Tesseract"""
return tesseract_predict.get_raw_mrz_text(
original_image, preprocessed_image, verbose=verbose
)
class EasyOcrOptions(TypedDict):
"""Options for the EasyOcr engine"""
class EasyOcr(Engine):
"""OCR engine using EasyOcr"""
def __init__(self, options: EasyOcrOptions):
self.options = options
def get_mrz_text(
self, original_image, preprocessed_image, verbose=False
) -> Optional[tuple[str, PostProcessorMetadata]]:
"""Get the raw MRZ text using EasyOcr"""
return easy_ocr_predict.get_raw_mrz_text(
original_image, preprocessed_image, verbose=verbose
)
class DeepLearningOptions(TypedDict):
"""Options for DeepLearning engine"""
class DeepLearning(Engine):
"""OCR engine using custom deeplearning model with TensorFlow"""
def __init__(self, options: DeepLearningOptions):
self.options = options
def get_mrz_text(
self, original_image, preprocessed_image, verbose=False
) -> Optional[tuple[str, PostProcessorMetadata]]:
"""Get the raw MRZ using TensorFlow deeplearning"""
return tensor_flow_predictor.make_prediction(
original_image, preprocessed_image, verbose
)