Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ regula/documentreader/webclient/gen/models/document_types_candidates.py
regula/documentreader/webclient/gen/models/document_types_candidates_list.py
regula/documentreader/webclient/gen/models/document_types_candidates_result.py
regula/documentreader/webclient/gen/models/document_types_candidates_result_all_of.py
regula/documentreader/webclient/gen/models/encrypted_rcl_result.py
regula/documentreader/webclient/gen/models/encrypted_rcl_result_all_of.py
regula/documentreader/webclient/gen/models/fdsid_list.py
regula/documentreader/webclient/gen/models/fiber_result.py
regula/documentreader/webclient/gen/models/fiber_result_all_of.py
Expand All @@ -66,6 +68,8 @@ regula/documentreader/webclient/gen/models/images_result_all_of.py
regula/documentreader/webclient/gen/models/lcid.py
regula/documentreader/webclient/gen/models/lexical_analysis_result.py
regula/documentreader/webclient/gen/models/lexical_analysis_result_all_of.py
regula/documentreader/webclient/gen/models/license_result.py
regula/documentreader/webclient/gen/models/license_result_all_of.py
regula/documentreader/webclient/gen/models/light.py
regula/documentreader/webclient/gen/models/list_verified_fields.py
regula/documentreader/webclient/gen/models/log_level.py
Expand Down
1 change: 1 addition & 0 deletions example/encrypted-rcl.txt

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions example/example-rcl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import os

from regula.documentreader.webclient import *
from regula.documentreader.webclient.ext.models.recognition_request import LicenseRequest, EncryptedRCLRequest

host = os.getenv("API_BASE_PATH", "https://api.regulaforensics.com")
regula_license = os.getenv("TEST_LICENSE", None) # optional, used here only for smoke test purposes

# read optional local license file
if os.path.isfile('regula.license') and os.access('regula.license', os.R_OK):
with open("regula.license", "rb") as f:
print("Found local license file. Using it for performing request...")
regula_license = f.read()

with open("license.txt", "r") as f:
license_ = f.read()

with open("encrypted-rcl.txt", "r") as f:
encrypted_rcl = f.read()

with DocumentReaderApi(host) as api:
api.license = regula_license

params = ProcessParams(
scenario=Scenario.FULL_PROCESS,
result_type_output=[
# actual results
Result.STATUS, Result.AUTHENTICITY, Result.TEXT, Result.IMAGES,
Result.DOCUMENT_TYPE, Result.DOCUMENT_TYPE_CANDIDATES, Result.IMAGE_QUALITY,
Result.DOCUMENT_POSITION,
# legacy results
Result.MRZ_TEXT, Result.VISUAL_TEXT, Result.BARCODE_TEXT, Result.RFID_TEXT,
Result.VISUAL_GRAPHICS, Result.BARCODE_GRAPHICS, Result.RFID_GRAPHICS,
Result.LEXICAL_ANALYSIS
]
)
request = RecognitionRequest(
process_params=params,
container_list=ContainerList([
LicenseRequest(license_),
EncryptedRCLRequest(encrypted_rcl)
])
)
response = api.process(request)

# status examples
response_status = response.status
doc_overall_status = "valid" if response_status.overall_status == CheckResult.OK else "not valid"

# text fields example
doc_number_field = response.text.get_field(TextFieldType.DOCUMENT_NUMBER)
doc_number_field_by_name = response.text.get_field_by_name("Document Number")

doc_number_mrz = doc_number_field.get_value()
doc_number_visual = doc_number_field.get_value(Source.VISUAL)
doc_number_visual_validity = doc_number_field.source_validity(Source.VISUAL)
doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ)
doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL)

doc_authenticity = response.authenticity()

doc_ir_b900 = doc_authenticity.ir_b900_checks \
if doc_authenticity is not None else None
# if FULL_PROCESS then auth is None

doc_ir_b900_blank = doc_ir_b900.checks_by_element(SecurityFeatureType.BLANK) \
if doc_authenticity is not None else None

doc_image_pattern = doc_authenticity.image_pattern_checks \
if doc_authenticity is not None else None

doc_image_pattern_blank = doc_image_pattern.checks_by_element(SecurityFeatureType.BLANK) \
if doc_authenticity is not None else None

# images fields example
document_image = response.images.get_field(GraphicFieldType.DOCUMENT_FRONT).get_value()
portrait_from_visual = response.images.get_field(GraphicFieldType.PORTRAIT).get_value(Source.VISUAL)
with open('portrait.jpg', 'wb') as f:
f.write(portrait_from_visual)
with open('document-image.jpg', 'wb') as f:
f.write(document_image)

print("""
---------------------------------------------------------------------------
Web API version: {ping_version}
---------------------------------------------------------------------------
Document Overall Status: {doc_overall_status}
Document Number Visual: {doc_number_visual}
Document Number MRZ: {doc_number_mrz}
Validity Of Document Number Visual: {doc_number_visual_validity}
Validity Of Document Number MRZ: {doc_number_mrz_validity}
MRZ-Visual values comparison: {doc_number_mrz_visual_matching}
---------------------------------------------------------------------------
""".format(
ping_version=api.ping().version,
doc_overall_status=doc_overall_status, doc_number_visual=doc_number_visual,
doc_number_mrz=doc_number_mrz, doc_number_visual_validity=doc_number_mrz_validity,
doc_number_mrz_validity=doc_number_mrz_validity, doc_number_mrz_visual_matching=doc_number_mrz_visual_matching,
))
1 change: 1 addition & 0 deletions example/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AAEAAK/WKOtEs17ikF4B/IKdpwmj9p0KTx2OSFFdNba1eoDT5+8tDMeZEM4ucNYB3zqKknTIxH/7zTNpQtFLtzZlwmtWEgwfLLSdFdWTA63AI7RjRxD9gr2ci++l32k7iJvUnLy1XAMM6sEhij4Ui3s+MpObMhu6/EJWe9y/57uFB4Jzdwx34D9VAS1wj9O6MliCqKs9sIZNwohaddcg8sVYHKd76VqVvrZKN5HcW7nSjWoDDXWsLA3LW6INaU3SuWJJkDD1EqE6lvjWjKlxwe7B5h77csirRjI58HCXrbXL1g84n1FZ3uTgw7KfISxlQ+i99Zj9TbhSEiGPfnZFvk6LHARUBAAAAAAAECcDDWmiV6FtvHfS/mQmG7iPG16AxSAM1CZkciHkBeXKD+P3qYfPPKvOoC+VmgsKy3+YtFZbNtdrzWILttCv9PDHshglkIaC5qIwJCJUwmj7o2LHMtLyVVzLq15v3JULQ89HGa0Mgcjoo4Rporb/ARsRq5f9YaEamP6i2zmc88Fa4a4pxl3bBI3pDlu6qZ2SGRyysrkh19PUf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lKe6zrluztm/gYO7h2Rt1ualZbO4DQvt8OuTwXvzxR1X9XWJ6qNZjYbMmnZp+tPpL+iO3St6sWWGEc5nelcCPOIBOoXwYo1SZxUa0ex//aiExfoaEL1aJO95ARWnKwXnVBJyEiRume5j/qFeFkwo5/XFiBt9bRluOMdWuNTOc5A25eFmuNr0n8eeE458Huyg7DiKQ==
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand All @@ -16,12 +17,60 @@ def __init__(self, image: Union[bytes, Base64String], light_index=None, page_ind
super().__init__(ImageData(image), light_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,
_buf_length,
_light,
_list_idx,
_page_idx,
_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__(
__encrypted_rcl,
_buf_length,
_light,
_list_idx,
_page_idx,
_result_type
)


class RecognitionRequest(ProcessRequest):
def __init__(self, process_params: ProcessParams, images: List[Union[RecognitionImage, bytes, Base64String]]):
def __init__(
self, process_params: ProcessParams,
images: List[Union[RecognitionImage, bytes, Base64String]] = None,
container_list: ContainerList = None
):
input_images = []
for image in images:
if isinstance(image, (bytes, str)):
input_images.append(RecognitionImage(image))
else:
input_images.append(image)
super().__init__(process_params, input_images, ProcessSystemInfo())
if images:
for image in images:
if isinstance(image, (bytes, str)):
input_images.append(RecognitionImage(image))
else:
input_images.append(image)
super().__init__(process_params, list=input_images, system_info=ProcessSystemInfo())
if container_list:
super().__init__(process_params, container_list=container_list, system_info=ProcessSystemInfo())
4 changes: 4 additions & 0 deletions regula/documentreader/webclient/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
from regula.documentreader.webclient.gen.models.document_types_candidates_list import DocumentTypesCandidatesList
from regula.documentreader.webclient.gen.models.document_types_candidates_result import DocumentTypesCandidatesResult
from regula.documentreader.webclient.gen.models.document_types_candidates_result_all_of import DocumentTypesCandidatesResultAllOf
from regula.documentreader.webclient.gen.models.encrypted_rcl_result import EncryptedRCLResult
from regula.documentreader.webclient.gen.models.encrypted_rcl_result_all_of import EncryptedRCLResultAllOf
from regula.documentreader.webclient.gen.models.fdsid_list import FDSIDList
from regula.documentreader.webclient.gen.models.fiber_result import FiberResult
from regula.documentreader.webclient.gen.models.fiber_result_all_of import FiberResultAllOf
Expand All @@ -84,6 +86,8 @@
from regula.documentreader.webclient.gen.models.lcid import LCID
from regula.documentreader.webclient.gen.models.lexical_analysis_result import LexicalAnalysisResult
from regula.documentreader.webclient.gen.models.lexical_analysis_result_all_of import LexicalAnalysisResultAllOf
from regula.documentreader.webclient.gen.models.license_result import LicenseResult
from regula.documentreader.webclient.gen.models.license_result_all_of import LicenseResultAllOf
from regula.documentreader.webclient.gen.models.light import Light
from regula.documentreader.webclient.gen.models.list_verified_fields import ListVerifiedFields
from regula.documentreader.webclient.gen.models.log_level import LogLevel
Expand Down
4 changes: 4 additions & 0 deletions regula/documentreader/webclient/gen/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
from regula.documentreader.webclient.gen.models.document_types_candidates_list import DocumentTypesCandidatesList
from regula.documentreader.webclient.gen.models.document_types_candidates_result import DocumentTypesCandidatesResult
from regula.documentreader.webclient.gen.models.document_types_candidates_result_all_of import DocumentTypesCandidatesResultAllOf
from regula.documentreader.webclient.gen.models.encrypted_rcl_result import EncryptedRCLResult
from regula.documentreader.webclient.gen.models.encrypted_rcl_result_all_of import EncryptedRCLResultAllOf
from regula.documentreader.webclient.gen.models.fdsid_list import FDSIDList
from regula.documentreader.webclient.gen.models.fiber_result import FiberResult
from regula.documentreader.webclient.gen.models.fiber_result_all_of import FiberResultAllOf
Expand All @@ -68,6 +70,8 @@
from regula.documentreader.webclient.gen.models.lcid import LCID
from regula.documentreader.webclient.gen.models.lexical_analysis_result import LexicalAnalysisResult
from regula.documentreader.webclient.gen.models.lexical_analysis_result_all_of import LexicalAnalysisResultAllOf
from regula.documentreader.webclient.gen.models.license_result import LicenseResult
from regula.documentreader.webclient.gen.models.license_result_all_of import LicenseResultAllOf
from regula.documentreader.webclient.gen.models.light import Light
from regula.documentreader.webclient.gen.models.list_verified_fields import ListVerifiedFields
from regula.documentreader.webclient.gen.models.log_level import LogLevel
Expand Down
Loading