-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrecognition_request.py
More file actions
executable file
·97 lines (86 loc) · 3.46 KB
/
Copy pathrecognition_request.py
File metadata and controls
executable file
·97 lines (86 loc) · 3.46 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import base64
from typing import List, Union
from regula.documentreader.webclient import LicenseResult, EncryptedRCLResult, ContainerList, Result
from regula.documentreader.webclient.gen.models import ImageData, ProcessParams
from regula.documentreader.webclient.gen.models.process_request import ProcessRequest
from regula.documentreader.webclient.gen.models.process_request_image import ProcessRequestImage
from regula.documentreader.webclient.gen.models.process_system_info import ProcessSystemInfo
Base64String = str
class RecognitionImage(ProcessRequestImage):
def __init__(self, image: Union[bytes, Base64String], light_index=None, page_index=None):
if isinstance(image, bytes):
image = base64.b64encode(image).decode("utf-8")
super().__init__(
ImageData = ImageData(image = image),
light = light_index,
page_index = page_index,
)
class LicenseRequest(LicenseResult):
def __init__(self, _license: Union[bytes, Base64String],
_light: int = None, _list_idx: int = None, _page_idx: int = None):
if isinstance(_license, bytes):
# if we need to encode
__license = base64.b64encode(_license).decode("uft-8")
else:
__license = _license
_buf_length = len(_license)
_result_type = Result.LICENSE
super().__init__(
License = __license,
buf_length = _buf_length,
light = _light,
list_idx = _list_idx,
page_idx = _page_idx,
result_type = _result_type
)
class EncryptedRCLRequest(EncryptedRCLResult):
def __init__(self, _encrypted_rcl: Union[bytes, Base64String] = None,
_light: int = None, _list_idx: int = None, _page_idx: int = None):
if isinstance(_encrypted_rcl, bytes):
# if we need to encode
__encrypted_rcl = base64.b64encode(_encrypted_rcl).decode("uft-8")
else:
__encrypted_rcl = _encrypted_rcl
_buf_length = len(_encrypted_rcl)
_result_type = Result.ENCRYPTED_RCL
super().__init__(
EncryptedRCL = __encrypted_rcl,
buf_length = _buf_length,
light = _light,
list_idx = _list_idx,
page_idx = _page_idx,
result_type = _result_type
)
class RecognitionRequest(ProcessRequest):
def __init__(
self,
process_params: ProcessParams,
images: List[Union[RecognitionImage, bytes, Base64String]] = None,
container_list: ContainerList = None, tag=None,
system_info: ProcessSystemInfo = ProcessSystemInfo(),
tenant: str = None, env: str = None
):
input_images = []
if images:
for image in images:
if isinstance(image, (bytes, str)):
input_images.append(RecognitionImage(image))
else:
input_images.append(image)
super().__init__(
processParam=process_params,
List=input_images,
systemInfo=system_info,
tag=tag,
tenant=tenant,
env=env
)
if container_list:
super().__init__(
processParam=process_params,
ContainerList=container_list,
systemInfo=system_info,
tag=tag,
tenant=tenant,
env=env
)