Skip to content

Commit ca963d2

Browse files
restore working proof of address
1 parent 5ba22f8 commit ca963d2

File tree

4 files changed

+233
-0
lines changed

4 files changed

+233
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---
2+
title: Proof of Address OCR Python
3+
category: 622b805aaec68102ea7fcbc2
4+
slug: python-proof-of-address-ocr
5+
parentDoc: 609808f773b0b90051d839de
6+
---
7+
The Python OCR SDK supports the [Proof of Address API](https://platform.mindee.com/mindee/proof_of_address).
8+
9+
Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/proof_of_address/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
10+
![Proof of Address sample](https://github.com/mindee/client-lib-test-data/blob/main/products/proof_of_address/default_sample.jpg?raw=true)
11+
12+
# Quick-Start
13+
```py
14+
from mindee import Client, PredictResponse, product
15+
16+
# Init a new client
17+
mindee_client = Client(api_key="my-api-key")
18+
19+
# Load a file from disk
20+
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
21+
22+
# Load a file from disk and parse it.
23+
# The endpoint name must be specified since it cannot be determined from the class.
24+
result: PredictResponse = mindee_client.parse(product.ProofOfAddressV1, input_doc)
25+
26+
# Print a summary of the API result
27+
print(result.document)
28+
29+
# Print the document-level summary
30+
# print(result.document.inference.prediction)
31+
32+
```
33+
34+
**Output (RST):**
35+
```rst
36+
########
37+
Document
38+
########
39+
:Mindee ID: 5d2361e9-405e-4fc1-8531-f92a3aef0c38
40+
:Filename: default_sample.jpg
41+
42+
Inference
43+
#########
44+
:Product: mindee/proof_of_address v1.1
45+
:Rotation applied: Yes
46+
47+
Prediction
48+
==========
49+
:Locale: en; en; USD;
50+
:Issuer Name: PPL ELECTRIC UTILITIES
51+
:Issuer Company Registrations:
52+
:Issuer Address: 2 NORTH 9TH STREET CPC-GENN1 ALLENTOWN.PA 18101-1175
53+
:Recipient Name:
54+
:Recipient Company Registrations:
55+
:Recipient Address: 123 MAIN ST ANYTOWN,PA 18062
56+
:Dates: 2011-07-27
57+
2011-07-06
58+
2011-08-03
59+
2011-07-27
60+
2011-06-01
61+
2011-07-01
62+
2010-07-01
63+
2010-08-01
64+
2011-07-01
65+
2009-08-01
66+
2010-07-01
67+
2011-07-27
68+
:Date of Issue: 2011-07-27
69+
70+
Page Predictions
71+
================
72+
73+
Page 0
74+
------
75+
:Locale: en; en; USD;
76+
:Issuer Name: PPL ELECTRIC UTILITIES
77+
:Issuer Company Registrations:
78+
:Issuer Address: 2 NORTH 9TH STREET CPC-GENN1 ALLENTOWN.PA 18101-1175
79+
:Recipient Name:
80+
:Recipient Company Registrations:
81+
:Recipient Address: 123 MAIN ST ANYTOWN,PA 18062
82+
:Dates: 2011-07-27
83+
2011-07-06
84+
2011-08-03
85+
2011-07-27
86+
2011-06-01
87+
2011-07-01
88+
2010-07-01
89+
2010-08-01
90+
2011-07-01
91+
2009-08-01
92+
2010-07-01
93+
2011-07-27
94+
:Date of Issue: 2011-07-27
95+
```
96+
97+
# Field Types
98+
## Standard Fields
99+
These fields are generic and used in several products.
100+
101+
### BaseField
102+
Each prediction object contains a set of fields that inherit from the generic `BaseField` class.
103+
A typical `BaseField` object will have the following attributes:
104+
105+
* **value** (`Union[float, str]`): corresponds to the field value. Can be `None` if no value was extracted.
106+
* **confidence** (`float`): the confidence score of the field prediction.
107+
* **bounding_box** (`[Point, Point, Point, Point]`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
108+
* **polygon** (`List[Point]`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
109+
* **page_id** (`int`): the ID of the page, always `None` when at document-level.
110+
* **reconstructed** (`bool`): indicates whether an object was reconstructed (not extracted as the API gave it).
111+
112+
> **Note:** A `Point` simply refers to a List of two numbers (`[float, float]`).
113+
114+
115+
Aside from the previous attributes, all basic fields have access to a custom `__str__` method that can be used to print their value as a string.
116+
117+
118+
### CompanyRegistrationField
119+
Aside from the basic `BaseField` attributes, the company registration field `CompanyRegistrationField` also implements the following:
120+
121+
* **type** (`str`): the type of company.
122+
123+
### DateField
124+
Aside from the basic `BaseField` attributes, the date field `DateField` also implements the following:
125+
126+
* **date_object** (`Date`): an accessible representation of the value as a python object. Can be `None`.
127+
128+
### LocaleField
129+
The locale field `LocaleField` only implements the **value**, **confidence** and **page_id** base `BaseField` attributes, but it comes with its own:
130+
131+
* **language** (`str`): ISO 639-1 language code (e.g.: `en` for English). Can be `None`.
132+
* **country** (`str`): ISO 3166-1 alpha-2 or ISO 3166-1 alpha-3 code for countries (e.g.: `GRB` or `GB` for "Great Britain"). Can be `None`.
133+
* **currency** (`str`): ISO 4217 code for currencies (e.g.: `USD` for "US Dollars"). Can be `None`.
134+
135+
### StringField
136+
The text field `StringField` only has one constraint: its **value** is an `Optional[str]`.
137+
138+
# Attributes
139+
The following fields are extracted for Proof of Address V1:
140+
141+
## Date of Issue
142+
**date** ([DateField](#datefield)): The date the document was issued.
143+
144+
```py
145+
print(result.document.inference.prediction.date.value)
146+
```
147+
148+
## Dates
149+
**dates** (List[[DateField](#datefield)]): List of dates found on the document.
150+
151+
```py
152+
for dates_elem in result.document.inference.prediction.dates:
153+
print(dates_elem.value)
154+
```
155+
156+
## Issuer Address
157+
**issuer_address** ([StringField](#stringfield)): The address of the document's issuer.
158+
159+
```py
160+
print(result.document.inference.prediction.issuer_address.value)
161+
```
162+
163+
## Issuer Company Registrations
164+
**issuer_company_registration** (List[[CompanyRegistrationField](#companyregistrationfield)]): List of company registrations found for the issuer.
165+
166+
```py
167+
for issuer_company_registration_elem in result.document.inference.prediction.issuer_company_registration:
168+
print(issuer_company_registration_elem.value)
169+
```
170+
171+
## Issuer Name
172+
**issuer_name** ([StringField](#stringfield)): The name of the person or company issuing the document.
173+
174+
```py
175+
print(result.document.inference.prediction.issuer_name.value)
176+
```
177+
178+
## Locale
179+
**locale** ([LocaleField](#localefield)): The locale detected on the document.
180+
181+
```py
182+
print(result.document.inference.prediction.locale.value)
183+
```
184+
185+
## Recipient Address
186+
**recipient_address** ([StringField](#stringfield)): The address of the recipient.
187+
188+
```py
189+
print(result.document.inference.prediction.recipient_address.value)
190+
```
191+
192+
## Recipient Company Registrations
193+
**recipient_company_registration** (List[[CompanyRegistrationField](#companyregistrationfield)]): List of company registrations found for the recipient.
194+
195+
```py
196+
for recipient_company_registration_elem in result.document.inference.prediction.recipient_company_registration:
197+
print(recipient_company_registration_elem.value)
198+
```
199+
200+
## Recipient Name
201+
**recipient_name** ([StringField](#stringfield)): The name of the person or company receiving the document.
202+
203+
```py
204+
print(result.document.inference.prediction.recipient_name.value)
205+
```
206+
207+
# Questions?
208+
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Proof of Address V1
2+
-------------------
3+
4+
**Sample Code:**
5+
6+
.. literalinclude:: /extras/code_samples/proof_of_address_v1.txt
7+
:language: Python
8+
9+
.. autoclass:: mindee.product.proof_of_address.proof_of_address_v1.ProofOfAddressV1
10+
:members:
11+
:inherited-members:
12+
13+
.. autoclass:: mindee.product.proof_of_address.proof_of_address_v1_document.ProofOfAddressV1Document
14+
:members:
15+
:inherited-members:

mindee/commands/cli_products.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ class CommandConfig(Generic[TypeInference]):
154154
is_sync=True,
155155
is_async=False,
156156
),
157+
"proof-of-address": CommandConfig(
158+
help="Proof of Address",
159+
doc_class=product.ProofOfAddressV1,
160+
is_sync=True,
161+
is_async=False,
162+
),
157163
"receipt": CommandConfig(
158164
help="Receipt",
159165
doc_class=product.ReceiptV5,

mindee/product/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
from mindee.product.passport.passport_v1_document import (
130130
PassportV1Document,
131131
)
132+
from mindee.product.proof_of_address.proof_of_address_v1 import ProofOfAddressV1
133+
from mindee.product.proof_of_address.proof_of_address_v1_document import (
134+
ProofOfAddressV1Document,
135+
)
132136
from mindee.product.receipt.receipt_v5 import ReceiptV5
133137
from mindee.product.receipt.receipt_v5_document import (
134138
ReceiptV5Document,

0 commit comments

Comments
 (0)