Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-19374: Update example #165

Merged
merged 1 commit into from
Nov 6, 2024
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
50 changes: 20 additions & 30 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,17 @@
"X-CLIENT-KEY": "123",
"Authorization": "Bearer 123"
}
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
]
)
params = ProcessParams(already_cropped=True, scenario=Scenario.FULL_PROCESS)

# Add license to request
# request = RecognitionRequest(system_info=ProcessSystemInfo(license="license"), process_params=params, images=[
# RecognitionImage(image=white_page_0, light_index=Light.WHITE, page_index=0),
# ])

request = RecognitionRequest(process_params=params, images=[
RecognitionImage(image=white_page_0, light_index=Light.WHITE, page_index=0),
RecognitionImage(image=ir_page_0, light_index=Light.IR, page_index=0),
RecognitionImage(image=uv_page_0, light_index=Light.UV, page_index=0),
# RecognitionImage(image=ir_page_0, light_index=Light.IR, page_index=0),
# RecognitionImage(image=uv_page_0, light_index=Light.UV, page_index=0),
])
response = api.process(request)

Expand All @@ -53,6 +47,7 @@
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")
Expand Down Expand Up @@ -85,21 +80,16 @@
f.write(portrait_from_visual)
with open('document-image.jpg', 'wb') as f:
f.write(document_image)

print("""
print(f"""
---------------------------------------------------------------------------
Web API version: {ping_version}
Web API version: {api.ping().version}
---------------------------------------------------------------------------
Document Overall Status: {doc_overall_status}
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,
))
Document Type: {response.result_by_type(result_type=Result.DOCUMENT_TYPE).one_candidate.document_name}
Validity Of Document Number Visual: {doc_number_visual_validity}
""")

print("-----------------------All Text Fields------------------------")
for field in response.text.field_list:
print(f"Source: {field.field_name}, Value: {field.value}")
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ def __init__(self, _encrypted_rcl: Union[bytes, Base64String] = None,

class RecognitionRequest(ProcessRequest):
def __init__(
self, process_params: ProcessParams,
self,
process_params: ProcessParams,
images: List[Union[RecognitionImage, bytes, Base64String]] = None,
container_list: ContainerList = None, tag=None
container_list: ContainerList = None, tag=None,
system_info: ProcessSystemInfo = ProcessSystemInfo(),
):
input_images = []
if images:
Expand All @@ -74,12 +76,12 @@ def __init__(
input_images.append(image)
super().__init__(
process_param=process_params, list=input_images,
system_info=ProcessSystemInfo(), tag=tag
system_info=system_info, tag=tag
)
if container_list:
super().__init__(
process_param=process_params, container_list=container_list,
system_info=ProcessSystemInfo(), tag=tag
system_info=system_info, tag=tag
)

@property
Expand Down
Loading