forked from linhub15/idify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure_id_document.py
98 lines (89 loc) · 3.83 KB
/
azure_id_document.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# import libraries
import os
from load_env import endpoint, key
from azure.ai.formrecognizer import DocumentAnalysisClient
from azure.core.credentials import AzureKeyCredential
def analyze_identity_documents():
# sample document
identityUrl = "https://www.alberta.ca/system/files/styles/responsive_1040/private/custom_downloaded_images/DL-Sally-Sample-AB-ID-Face-V8b-Sally-Sample.jpg?itok=5NbxXkry"
document_analysis_client = DocumentAnalysisClient(
endpoint=endpoint, credential=AzureKeyCredential(key)
)
poller = document_analysis_client.begin_analyze_document_from_url(
"prebuilt-idDocument", identityUrl
)
id_documents = poller.result()
for idx, id_document in enumerate(id_documents.documents):
# # print("Fields from ID document: ", id_document.fields)
# print("--------Analyzing ID document #{}--------".format(idx + 1))
# first_name = id_document.fields.get("FirstName")
# if first_name:
# print(
# "First Name: {} has confidence: {}".format(
# first_name.value, first_name.confidence
# )
# )
# last_name = id_document.fields.get("LastName")
# if last_name:
# print(
# "Last Name: {} has confidence: {}".format(
# last_name.value, last_name.confidence
# )
# )
# document_number = id_document.fields.get("DocumentNumber")
# if document_number:
# print(
# "Document Number: {} has confidence: {}".format(
# document_number.value, document_number.confidence
# )
# )
# dob = id_document.fields.get("DateOfBirth")
# if dob:
# print(
# "Date of Birth: {} has confidence: {}".format(dob.value, dob.confidence)
# )
# doe = id_document.fields.get("DateOfExpiration")
# if doe:
# print(
# "Date of Expiration: {} has confidence: {}".format(
# doe.value, doe.confidence
# )
# )
# sex = id_document.fields.get("Sex")
# if sex:
# print("Sex: {} has confidence: {}".format(sex.value, sex.confidence))
# address = id_document.fields.get("Address")
# if address:
# print(
# "Address: {} has confidence: {}".format(
# address.value, address.confidence
# )
# )
# country_region = id_document.fields.get("CountryRegion")
# if country_region:
# print(
# "Country/Region: {} has confidence: {}".format(
# country_region.value, country_region.confidence
# )
# )
# region = id_document.fields.get("Region")
# if region:
# print(
# "Region: {} has confidence: {}".format(region.value, region.confidence)
# )
# print("--------------------------------------")
user_data = {
"first_name": id_document.fields.get("FirstName").value,
"last_name": id_document.fields.get("LastName").value,
"license_number": id_document.fields.get("DocumentNumber").value,
"dob": id_document.fields.get("DateOfBirth").value,
"doe": id_document.fields.get("DateOfExpiration").value,
"sex": id_document.fields.get("Sex").value,
"address": id_document.fields.get("Address").value,
"postal_code": id_document.fields.get("PostalCode").value,
"country": id_document.fields.get("Country").value,
"region": id_document.fields.get("Region").value
}
print(user_data)
if __name__ == "__main__":
analyze_identity_documents()