|
1 | | -# Regula Document Reader web application python client |
| 1 | +# Regula Document Reader web API Python 3.5+ client |
| 2 | + |
| 3 | +[](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation) |
| 4 | +[](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation) |
| 5 | +[](https://github.com/regulaforensics/DocumentReader-web-openapi) |
| 6 | + |
| 7 | +Documents recognition as easy as reading two bytes. |
| 8 | + |
| 9 | +If you have any problems with or questions about this client, please contact us |
| 10 | +through a [GitHub issue](https://github.com/regulaforensics/DocumentReader-web-python-client/issues). |
| 11 | +You are invited to contribute [new features, fixes, or updates](https://github.com/regulaforensics/DocumentReader-web-python-client/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22), large or small; We are always thrilled to receive pull requests, and do our best to process them as fast as we can. |
| 12 | + |
| 13 | +## Install package |
| 14 | +`regula.documentreader.webclient` is on the Python Package Index (PyPI): |
| 15 | + |
| 16 | +```bash |
| 17 | +pip install regula.documentreader.webclient |
| 18 | +``` |
| 19 | + |
| 20 | +Or using `pipenv` |
| 21 | +```bash |
| 22 | +pipenv install regula.documentreader.webclient |
| 23 | +``` |
| 24 | + |
| 25 | +## Example |
| 26 | +Performing request: |
| 27 | +```python |
| 28 | +from regula.documentreader.webclient.ext.api import DocumentReaderApi |
| 29 | +from regula.documentreader.webclient.ext.models import * |
| 30 | +from regula.documentreader.webclient.gen.models import * |
| 31 | + |
| 32 | +with open("australia_passport.jpg", "rb") as f: |
| 33 | + input_image = f.read() |
| 34 | + |
| 35 | +with DocumentReaderApi(host='http://localhost:8080') as api: |
| 36 | + params = ProcessParams( |
| 37 | + scenario=Scenario.FULL_PROCESS, |
| 38 | + result_type_output=[Result.RAW_IMAGE, Result.STATUS, Result.TEXT, Result.IMAGES] |
| 39 | + ) |
| 40 | + request = RecognitionRequest(process_params=params, images=[input_image]) |
| 41 | + response = api.process(request) |
| 42 | +``` |
| 43 | + |
| 44 | +Parsing results: |
| 45 | +```python |
| 46 | +# status examples |
| 47 | +response_status = response.status |
| 48 | +doc_overall_status = "valid" if response_status.overall_status == CheckResult.OK else "not valid" |
| 49 | + |
| 50 | +# text fields example |
| 51 | +doc_number_field = response.text.get_field(TextFieldType.DOCUMENT_NUMBER) |
| 52 | +doc_number_mrz = doc_number_field.get_value() |
| 53 | +doc_number_visual = doc_number_field.get_value(Source.VISUAL) |
| 54 | +doc_number_visual_validity = doc_number_field.source_validity(Source.VISUAL) |
| 55 | +doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ) |
| 56 | +doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL) |
| 57 | + |
| 58 | +# images fields example |
| 59 | +normalized_input_image = response.images.normalized_input_image() |
| 60 | +portrait_field = response.images.get_field(GraphicFieldType.PORTRAIT) |
| 61 | +portrait_from_visual = portrait_field.get_value(Source.VISUAL) |
| 62 | +portrait_from_rfid = portrait_field.get_value(Source.RFID, original=True) |
| 63 | +``` |
| 64 | +You can find more detailed guide and run this sample in [example](./example) folder. |
2 | 65 |
|
3 | 66 | ## Development |
4 | 67 |
|
5 | | -To regenerate models from openapi definition, |
6 | | -clone [latest open api definitions](https://github.com/regulaforensics/DocumentReader-api-openapi) |
| 68 | +To regenerate models, clone [latest OpenAPI definitions](https://github.com/regulaforensics/DocumentReader-web-openapi) |
7 | 69 | and set `DEFINITION_FOLDER` as path to cloned directory, for example: |
8 | 70 | ```bash |
9 | | -DEFINITION_FOLDER="/home/user/projects/DocumentReader-api-openapi" |
| 71 | +DEFINITION_FOLDER="/home/user/projects/DocumentReader-web-openapi" |
10 | 72 | ``` |
11 | 73 | Then use next command from the project root: |
12 | 74 | ```bash |
|
0 commit comments