Skip to content

Commit 74b3e0f

Browse files
committed
Enhance documentation
1 parent 95a2391 commit 74b3e0f

File tree

5 files changed

+117
-23
lines changed

5 files changed

+117
-23
lines changed

README.md

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,74 @@
1-
# Regula Document Reader web application python client
1+
# Regula Document Reader web API Python 3.5+ client
2+
3+
[![pypi](https://img.shields.io/pypi/v/regula.documentreader.webclient?style=flat-square)](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation)
4+
[![documentation](https://img.shields.io/badge/docs-en-f6858d?style=flat-square)](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation)
5+
[![OpenAPI](https://img.shields.io/badge/OpenAPI-defs-0a8c42?style=flat-square)](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.
265

366
## Development
467

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)
769
and set `DEFINITION_FOLDER` as path to cloned directory, for example:
870
```bash
9-
DEFINITION_FOLDER="/home/user/projects/DocumentReader-api-openapi"
71+
DEFINITION_FOLDER="/home/user/projects/DocumentReader-web-openapi"
1072
```
1173
Then use next command from the project root:
1274
```bash

example/Pipfile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,5 @@ url = "https://pypi.python.org/simple"
33
verify_ssl = true
44
name = "pypi"
55

6-
[[source]]
7-
url = "https://test.pypi.org/simple/"
8-
verify_ssl = true
9-
name = "test-pypi"
10-
116
[packages]
127
"regula.documentreader.webclient" = {editable = true,path = "./.."}
13-
14-
[requires]
15-
python_version = "3.5"

example/Pipfile.lock

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Regula Document Reader web API Python 3.5+ client
2+
3+
## Running example
4+
5+
Requirements:
6+
- installed python 3.5 or higher
7+
- installed [pipenv](https://pypi.org/project/pipenv)
8+
- running Regula Document Reader web application(todo link for docker run?) with trial license(todo edit desc here)
9+
10+
Cloning example
11+
```bash
12+
git clone https://github.com/regulaforensics/DocumentReader-web-python-client.git
13+
cd example
14+
```
15+
16+
Setup project and download dependencies:
17+
```bash
18+
pipenv install
19+
```
20+
21+
Run example:
22+
```bash
23+
pipenv run python example.py
24+
25+
# If Regula Document Reader web API is running not on localhost, also specify host via env variable:
26+
API_BASE_PATH="http://192.168.0.101:8080" pipenv run python example.py
27+
```
28+
29+
This sample generate next text output:
30+
```text
31+
---------------------------------------------------------------------------
32+
Document Overall Status: not valid
33+
Document Number Visual: U0996738
34+
Document Number MRZ: U0996738
35+
Validity Of Document Number Visual: 1
36+
Validity Of Document Number MRZ: 1
37+
MRZ-Visual values comparison: 1
38+
---------------------------------------------------------------------------
39+
```
40+
Also, it creates [portrait](portraitFromVisual.jpg) and [normalized input](normalizedInputImage.jpg)
41+
pictures inside current folder.
42+
43+
Edit on your own [example.py](./example.py), and re-run to see your results.
44+
45+
## Detailed guide
46+
47+
tbd

example/example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
# text fields example
2929
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)
30+
doc_number_mrz = doc_number_field.get_value()
31+
doc_number_visual = doc_number_field.get_value(Source.VISUAL)
3232
doc_number_visual_validity = doc_number_field.source_validity(Source.VISUAL)
3333
doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ)
3434
doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL)

0 commit comments

Comments
 (0)