Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexample.py
More file actions
Latest commit
executable file
·82 lines (63 loc) · 3.46 KB
/
Copy pathexample.py
File metadata and controls
executable file
·82 lines (63 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
importos
fromregula.documentreader.webclientimport*
host=os.getenv("API_BASE_PATH", "https://api.regulaforensics.com")
withopen("WHITE.jpg", "rb") asf:
white_page_0=f.read()
withopen("IR.jpg", "rb") asf:
ir_page_0=f.read()
withopen("UV.jpg", "rb") asf:
uv_page_0=f.read()
withDocumentReaderApi(host) asapi:
api.api_client.default_headers= {
"X-CLIENT-KEY": "123",
"Authorization": "Bearer 123"
}
params=ProcessParams(alreadyCropped=True, scenario=Scenario.FULL_PROCESS)
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),
])
response=api.process(request)
request_json=request.to_json() # example for request & response raw json
response_json=response.to_json()
# status examples
response_status=response.status
doc_overall_status="valid"ifresponse_status.overall_status==CheckResult.OKelse"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 \
ifdoc_authenticityisnotNoneelseNone
# if FULL_PROCESS then auth is None
doc_ir_b900_blank=doc_ir_b900.checks_by_element(SecurityFeatureType.BLANK) \
ifdoc_ir_b900isnotNoneelseNone
doc_image_pattern=doc_authenticity.image_pattern_checks \
ifdoc_authenticityisnotNoneelseNone
doc_image_pattern_blank=doc_image_pattern.checks_by_element(SecurityFeatureType.BLANK) \
ifdoc_image_patternisnotNoneelseNone
# 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)
withopen('portrait.jpg', 'wb') asf:
f.write(portrait_from_visual)
withopen('document-image.jpg', 'wb') asf:
f.write(document_image)
print(f"""
---------------------------------------------------------------------------
Web API version: {api.healthz().version}
---------------------------------------------------------------------------
Document Overall Status: {doc_overall_status}
Document Number Visual: {doc_number_visual}
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------------------------")
forfieldinresponse.text.field_list:
print(f"Source: {field.field_name}, Value: {field.value}")