|
1 | 1 | import os |
2 | 2 |
|
3 | 3 | from regula.documentreader.webclient.ext.api import DocumentReaderApi |
4 | | -from regula.documentreader.webclient.ext.models import RecognitionImage, RecognitionRequest |
5 | | -from regula.documentreader.webclient.gen import ProcessParams, Scenario, Result, Light, TextFieldType, Source, \ |
| 4 | +from regula.documentreader.webclient.ext.models import RecognitionRequest |
| 5 | +from regula.documentreader.webclient.gen import ProcessParams, Scenario, Result, TextFieldType, Source, \ |
6 | 6 | CheckResult |
7 | 7 |
|
8 | 8 | host = os.getenv("API_BASE_PATH", "http://localhost:8080") |
9 | | -license = os.getenv("TEST_LICENSE", None) |
| 9 | +license = os.getenv("TEST_LICENSE", None) # optional, used here only for smoke test purposes |
10 | 10 |
|
11 | 11 | with open("australia_passport.jpg", "rb") as f: |
12 | | - image_payload = f.read() |
| 12 | + input_image = f.read() |
13 | 13 |
|
14 | 14 | with DocumentReaderApi(host) as api: |
15 | | - api.license = license |
16 | | - |
17 | | - process_params = ProcessParams(Scenario.FULL_PROCESS, [Result.STATUS, Result.TEXT, Result.IMAGES, 6]) |
18 | | - process_images = [RecognitionImage(image_payload, Light.WHITE)] |
19 | | - request = RecognitionRequest(process_params, process_images) |
| 15 | + api.license = license # used here only for smoke test purposes, most of clients will attach license on server side |
20 | 16 |
|
| 17 | + params = ProcessParams( |
| 18 | + scenario=Scenario.FULL_PROCESS, |
| 19 | + result_type_output=[Result.STATUS, Result.TEXT, Result.IMAGES] |
| 20 | + ) |
| 21 | + request = RecognitionRequest(process_params=params, images=[input_image]) |
21 | 22 | response = api.process(request) |
22 | | - response.result_by_type(Result.IMAGES) |
23 | | - |
24 | | - response_text = response.text |
25 | | - |
26 | | - doc_number_field = response_text.get_field(TextFieldType.DOCUMENT_NUMBER) |
27 | | - |
28 | | - doc_number_visual = doc_number_field.get_value(Source.VISUAL) |
29 | | - doc_number_mrz = doc_number_field.get_value(Source.MRZ) |
30 | | - |
31 | | - doc_number_visual_validity = doc_number_field.get_validity(Source.VISUAL) |
32 | | - doc_number_mrz_validity = doc_number_field.get_validity(Source.MRZ) |
33 | | - |
34 | | - doc_number_mrz_visual_matching = doc_number_field.get_comparison(Source.MRZ, Source.VISUAL) |
35 | 23 |
|
| 24 | + # status examples |
36 | 25 | response_status = response.status |
37 | 26 | doc_overall_status = "valid" if response_status.overall_status == CheckResult.OK else "not valid" |
38 | 27 |
|
| 28 | + # text fields example |
| 29 | + doc_number_field = response.text.get_field(TextFieldType.DOCUMENT_NUMBER) |
| 30 | + doc_number_visual = doc_number_field.get_value() |
| 31 | + doc_number_mrz = doc_number_field.get_value(Source.MRZ) |
| 32 | + doc_number_visual_validity = doc_number_field.source_validity(Source.VISUAL) |
| 33 | + doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ) |
| 34 | + doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL) |
| 35 | + |
39 | 36 | response_images = response.images |
40 | 37 |
|
41 | 38 | print(""" |
|
0 commit comments