document-analyzer 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- document_analyzer/__init__.py +31 -0
- document_analyzer/__main__.py +5 -0
- document_analyzer/analyzers/__init__.py +14 -0
- document_analyzer/analyzers/cedula_analyzer.py +412 -0
- document_analyzer/analyzers/document_analyzer.py +187 -0
- document_analyzer/analyzers/passport_analyzer.py +294 -0
- document_analyzer/cli.py +401 -0
- document_analyzer/config/__init__.py +30 -0
- document_analyzer/config/constants.py +230 -0
- document_analyzer/config/logger.py +36 -0
- document_analyzer/services/__init__.py +3 -0
- document_analyzer/services/paddleocr_service.py +107 -0
- document_analyzer/startup.py +24 -0
- document_analyzer/utils/__init__.py +57 -0
- document_analyzer/utils/cedula_utils.py +155 -0
- document_analyzer/utils/common_utils.py +229 -0
- document_analyzer/utils/extract_cedula_signature.py +431 -0
- document_analyzer/utils/passport_language_detector.py +277 -0
- document_analyzer/utils/passport_utils.py +260 -0
- document_analyzer-0.1.0.dist-info/METADATA +520 -0
- document_analyzer-0.1.0.dist-info/RECORD +25 -0
- document_analyzer-0.1.0.dist-info/WHEEL +5 -0
- document_analyzer-0.1.0.dist-info/entry_points.txt +2 -0
- document_analyzer-0.1.0.dist-info/licenses/LICENSE +201 -0
- document_analyzer-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: document-analyzer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package for extracting information from Panamanian identity document (Cédula) and Passports
|
|
5
|
+
Author: Usman Ghani
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright [yyyy] [name of copyright owner]
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
|
207
|
+
|
|
208
|
+
Project-URL: Homepage, https://github.com/usman-369/document-analyzer
|
|
209
|
+
Project-URL: Repository, https://github.com/usman-369/document-analyzer
|
|
210
|
+
Project-URL: Issues, https://github.com/usman-369/document-analyzer/issues
|
|
211
|
+
Requires-Python: <=3.12,>=3.8
|
|
212
|
+
Description-Content-Type: text/markdown
|
|
213
|
+
License-File: LICENSE
|
|
214
|
+
Requires-Dist: paddleocr==3.2.0
|
|
215
|
+
Dynamic: license-file
|
|
216
|
+
|
|
217
|
+
# Document Analyzer
|
|
218
|
+
|
|
219
|
+
Document Analyzer is a Python package for extracting structured information from identity documents using [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR). It supports Panamanian ID cards (Cédulas) in Spanish, and passports with standard ICAO Machine Readable Zones (MRZ) in Spanish or English. The package automatically detects the document type and language, loading the appropriate OCR instance accordingly. It is specifically designed to work with mobile phone photos of documents rather than scans or PDFs, and includes automatic image preprocessing to improve extraction accuracy from lower-quality images.
|
|
220
|
+
|
|
221
|
+
## Version
|
|
222
|
+
|
|
223
|
+
Current version: **0.1.0** — Initial release.
|
|
224
|
+
|
|
225
|
+
## Features
|
|
226
|
+
|
|
227
|
+
- **Cédula Extraction** — Extract ID number, date of birth, place of birth, expiry date, and handwritten signature detection from Panamanian identity cards
|
|
228
|
+
- **Passport Extraction** — Extract ID number, date of birth, place of birth, nationality, and expiry date from passports with standard ICAO Machine Readable Zones (MRZ). Works with any country's passport that follows the ICAO standard format.
|
|
229
|
+
- **Automatic Document Detection** — Intelligently detect whether an image contains a Cédula or Passport
|
|
230
|
+
- **Image Preprocessing** — Automatically enhance poor quality images before OCR processing
|
|
231
|
+
- **CLI Support** — Full command-line interface for document analysis without writing code
|
|
232
|
+
- **JSON Output** — Structured JSON results for easy integration into other systems
|
|
233
|
+
- **Multi-Language Support** — Cédulas are processed in Spanish only. Passports support automatic language detection between Spanish and English, with the appropriate PaddleOCR instance loaded based on detected language.
|
|
234
|
+
|
|
235
|
+
## Requirements
|
|
236
|
+
|
|
237
|
+
- Python 3.8 to 3.12
|
|
238
|
+
- PaddleOCR 3.2.0
|
|
239
|
+
|
|
240
|
+
## Installation
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
pip install document-analyzer
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## CLI Usage
|
|
247
|
+
|
|
248
|
+
The package includes a command-line interface accessible via the `document-analyzer` command.
|
|
249
|
+
|
|
250
|
+
### Basic Usage with Auto-Detection
|
|
251
|
+
|
|
252
|
+
Analyze a document with automatic type detection:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
document-analyzer analyze photo.jpg
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
The output is printed as JSON to stdout.
|
|
259
|
+
|
|
260
|
+
### Specify Document Type
|
|
261
|
+
|
|
262
|
+
If you know the document type, you can skip auto-detection for faster processing:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
document-analyzer analyze cedula.jpg --type cedula
|
|
266
|
+
document-analyzer analyze passport.jpg --type passport
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Save Output to File
|
|
270
|
+
|
|
271
|
+
Save analysis results to a JSON file instead of printing to stdout:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
document-analyzer analyze photo.jpg --save result.json
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Verbose Mode
|
|
278
|
+
|
|
279
|
+
Enable debug-level logging to see detailed processing information:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
document-analyzer analyze photo.jpg -v
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Combine with `--save` for logging while saving results:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
document-analyzer analyze photo.jpg --save result.json -v
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Help
|
|
292
|
+
|
|
293
|
+
View all available options:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
document-analyzer analyze --help
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Library Usage
|
|
300
|
+
|
|
301
|
+
You can use Document Analyzer as a Python library in your own code. Here are examples for the main use cases.
|
|
302
|
+
|
|
303
|
+
### Auto-Detection with DocumentAnalyzer
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
from document_analyzer import DocumentAnalyzer
|
|
307
|
+
|
|
308
|
+
# Initialize with image path
|
|
309
|
+
analyzer = DocumentAnalyzer("photo.jpg")
|
|
310
|
+
|
|
311
|
+
# Detect document type
|
|
312
|
+
doc_type = analyzer.detect_document_type()
|
|
313
|
+
print(f"Detected: {doc_type}") # "cedula" or "passport" or "unknown"
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Extract from Cédula
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
from document_analyzer import CedulaAnalyzer
|
|
320
|
+
|
|
321
|
+
# Initialize with image path
|
|
322
|
+
analyzer = CedulaAnalyzer("cedula.jpg")
|
|
323
|
+
|
|
324
|
+
# Analyze the document
|
|
325
|
+
results = analyzer.analyze_cedula()
|
|
326
|
+
print(results)
|
|
327
|
+
|
|
328
|
+
# Optional: provide user email for logging context
|
|
329
|
+
analyzer = CedulaAnalyzer("cedula.jpg", user_email="user@example.com")
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Extract from Passport
|
|
333
|
+
|
|
334
|
+
```python
|
|
335
|
+
from document_analyzer import PassportAnalyzer
|
|
336
|
+
|
|
337
|
+
# Initialize with image path
|
|
338
|
+
analyzer = PassportAnalyzer("passport.jpg")
|
|
339
|
+
|
|
340
|
+
# Analyze the document
|
|
341
|
+
results = analyzer.analyze_passport()
|
|
342
|
+
print(results)
|
|
343
|
+
|
|
344
|
+
# Optional: provide user email for logging context
|
|
345
|
+
analyzer = PassportAnalyzer("passport.jpg", user_email="user@example.com")
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Convenience Functions
|
|
349
|
+
|
|
350
|
+
You can also use high-level functions for simpler code:
|
|
351
|
+
|
|
352
|
+
```python
|
|
353
|
+
from document_analyzer import analyze_document, analyze_cedula, analyze_passport
|
|
354
|
+
|
|
355
|
+
# Auto-detect and analyze
|
|
356
|
+
result = analyze_document("photo.jpg")
|
|
357
|
+
|
|
358
|
+
# Analyze specific document type
|
|
359
|
+
cedula_result = analyze_cedula("cedula.jpg")
|
|
360
|
+
passport_result = analyze_passport("passport.jpg")
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Output
|
|
364
|
+
|
|
365
|
+
Analysis results are returned as dictionaries containing structured information about the extracted data. Below are example outputs for both document types with realistic but fictional Panamanian data.
|
|
366
|
+
|
|
367
|
+
### Cédula Output Example
|
|
368
|
+
|
|
369
|
+
```json
|
|
370
|
+
{
|
|
371
|
+
"success": "both",
|
|
372
|
+
"cedula_info": {
|
|
373
|
+
"type": "cedula",
|
|
374
|
+
"id_number": "8-123-456",
|
|
375
|
+
"dob": "15-May-1990",
|
|
376
|
+
"pob": "Panama",
|
|
377
|
+
"nationality": "Panamanian",
|
|
378
|
+
"expiry": "22-Mar-2030"
|
|
379
|
+
},
|
|
380
|
+
"signature": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
The `success` field can be `"both"` (all info + signature), `"cedula_info"` (all info but no signature), `"signature"` (signature only), or `"none"` (extraction failed).
|
|
385
|
+
|
|
386
|
+
### Passport Output Example
|
|
387
|
+
|
|
388
|
+
```json
|
|
389
|
+
{
|
|
390
|
+
"success": "passport_info",
|
|
391
|
+
"passport_info": {
|
|
392
|
+
"type": "passport",
|
|
393
|
+
"id_number": "PA123456789",
|
|
394
|
+
"dob": "20-Nov-1988",
|
|
395
|
+
"pob": "Colón",
|
|
396
|
+
"nationality": "PAN",
|
|
397
|
+
"expiry": "10-Sep-2032"
|
|
398
|
+
},
|
|
399
|
+
"signature": null
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
The `success` field can be `"passport_info"` (extraction successful) or `"none"` (extraction failed).
|
|
404
|
+
|
|
405
|
+
## Image Requirements
|
|
406
|
+
|
|
407
|
+
Document Analyzer is designed to work with mobile phone photos of documents. Here are the technical requirements:
|
|
408
|
+
|
|
409
|
+
- **Supported Formats** — JPEG, PNG, BMP, TIFF, GIF
|
|
410
|
+
- **Orientation** — Portrait orientation works best
|
|
411
|
+
- **Quality** — Mobile phone camera quality is acceptable; the package includes automatic preprocessing to handle lower quality images
|
|
412
|
+
- **Coverage** — Entire document should be visible in the frame
|
|
413
|
+
- **Lighting** — Avoid strong shadows or glare across the document
|
|
414
|
+
|
|
415
|
+
The package includes automatic image preprocessing that attempts to enhance poor quality images before OCR processing. This can help improve accuracy for images with:
|
|
416
|
+
|
|
417
|
+
- Low contrast
|
|
418
|
+
- Poor lighting conditions
|
|
419
|
+
- Motion blur
|
|
420
|
+
- Dust or slight damage
|
|
421
|
+
|
|
422
|
+
**Note on PDFs:** PDF files are not listed in supported formats because they have not been tested. PDFs are not officially supported and may not work as expected. Use image files (JPG, PNG, etc.) for best results.
|
|
423
|
+
|
|
424
|
+
## GPU Acceleration
|
|
425
|
+
|
|
426
|
+
PaddleOCR supports GPU acceleration via CUDA for significantly faster processing on NVIDIA GPUs. However, Document Analyzer has only been tested and validated on CPU hardware (Intel i5, 10th generation).
|
|
427
|
+
|
|
428
|
+
If you want to experiment with GPU acceleration, you will need to:
|
|
429
|
+
|
|
430
|
+
1. Configure PaddleOCR to use your CUDA-enabled GPU according to the PaddleOCR documentation
|
|
431
|
+
2. Ensure your system has CUDA and cuDNN properly configured
|
|
432
|
+
3. Test thoroughly in your environment before deploying to production
|
|
433
|
+
|
|
434
|
+
CPU processing is stable and recommended for production use.
|
|
435
|
+
|
|
436
|
+
## Logging
|
|
437
|
+
|
|
438
|
+
Document Analyzer uses Python's standard `logging` module with the logger namespace `document_analyzer`. This allows you to configure logging behavior in your own applications.
|
|
439
|
+
|
|
440
|
+
### Basic Configuration
|
|
441
|
+
|
|
442
|
+
```python
|
|
443
|
+
import logging
|
|
444
|
+
|
|
445
|
+
# Enable debug logging from document_analyzer
|
|
446
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
### Django Configuration
|
|
450
|
+
|
|
451
|
+
If you're using Django and want to capture logs from Document Analyzer, add this to your `settings.py`:
|
|
452
|
+
|
|
453
|
+
```python
|
|
454
|
+
LOGGING = {
|
|
455
|
+
'version': 1,
|
|
456
|
+
'disable_existing_loggers': False,
|
|
457
|
+
'handlers': {
|
|
458
|
+
'console': {
|
|
459
|
+
'class': 'logging.StreamHandler',
|
|
460
|
+
},
|
|
461
|
+
'file': {
|
|
462
|
+
'class': 'logging.FileHandler',
|
|
463
|
+
'filename': 'document_analyzer.log',
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
'loggers': {
|
|
467
|
+
'document_analyzer': {
|
|
468
|
+
'handlers': ['console', 'file'],
|
|
469
|
+
'level': 'DEBUG',
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### Flask Configuration
|
|
476
|
+
|
|
477
|
+
For Flask applications:
|
|
478
|
+
|
|
479
|
+
```python
|
|
480
|
+
import logging
|
|
481
|
+
from logging.handlers import RotatingFileHandler
|
|
482
|
+
|
|
483
|
+
if not app.debug:
|
|
484
|
+
handler = RotatingFileHandler('document_analyzer.log', maxBytes=10000000, backupCount=10)
|
|
485
|
+
handler.setLevel(logging.DEBUG)
|
|
486
|
+
app.logger.addHandler(handler)
|
|
487
|
+
|
|
488
|
+
# Get the document_analyzer logger
|
|
489
|
+
doc_logger = logging.getLogger('document_analyzer')
|
|
490
|
+
doc_logger.addHandler(handler)
|
|
491
|
+
doc_logger.setLevel(logging.DEBUG)
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
## Limitations
|
|
495
|
+
|
|
496
|
+
Be aware of the following limitations when using Document Analyzer:
|
|
497
|
+
|
|
498
|
+
- **Cédula Support** — Cédula extraction is specifically designed for Panamanian identity cards in Spanish only. Non-Panamanian identity documents are not supported. Passport extraction works with any standard ICAO MRZ passport regardless of country.
|
|
499
|
+
|
|
500
|
+
- **Cédula Language** — Panamanian Cédulas are processed in Spanish only. English or other languages are not supported for Cédulas.
|
|
501
|
+
|
|
502
|
+
- **Image Quality Dependency** — Extraction accuracy depends on image quality. Very poor lighting, severe blur, or damaged documents may produce incomplete or inaccurate results. While the package includes preprocessing to improve poor quality images, there are limits to what can be recovered.
|
|
503
|
+
|
|
504
|
+
- **PDF Support Not Tested** — PDFs are not officially supported and have not been tested. The package is designed for and tested with image files (JPG, PNG, etc.).
|
|
505
|
+
|
|
506
|
+
- **Passport MRZ Dependency** — Passport extraction relies primarily on the Machine Readable Zone (MRZ) at the bottom of the document page. If the MRZ is obscured, cut off, or damaged in the photo, extraction accuracy will be significantly affected. Ensure the entire document including the bottom strip is clearly visible in the frame.
|
|
507
|
+
|
|
508
|
+
- **Place of Birth for Non-Panamanian Passports** — Place of birth is the only passport field extracted from the document's written fields rather than the MRZ. This works reliably for Panamanian passports. For other countries it may be inaccurate or missing depending on how that country formats and labels the biographical page of their passport.
|
|
509
|
+
|
|
510
|
+
- **CPU Testing Only** — The package has only been tested on CPU hardware (Intel i5, 10th generation). GPU acceleration via CUDA may work but is not officially supported or validated.
|
|
511
|
+
|
|
512
|
+
## License
|
|
513
|
+
|
|
514
|
+
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
|
|
515
|
+
|
|
516
|
+
## Author
|
|
517
|
+
|
|
518
|
+
- **Name:** Usman Ghani
|
|
519
|
+
- **GitHub:** [usman-369](https://github.com/usman-369)
|
|
520
|
+
- 
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
document_analyzer/__init__.py,sha256=fZWvRDs3MhjrwRu7neLkbAQ5PBh-69POXHWwsa7toDk,644
|
|
2
|
+
document_analyzer/__main__.py,sha256=R8toRIEpaunLvLRpFhTKF4x0aBUmBLoqHo0IrF4wuTw,82
|
|
3
|
+
document_analyzer/cli.py,sha256=9Ui1eEGJhhifsyxwlh3uG6c9fnSQ38pPbeMYMbfCanM,12508
|
|
4
|
+
document_analyzer/startup.py,sha256=AuEJ99jJdzv54LkTYn8IL5fZ-RoGK30ffv71w6peS9A,924
|
|
5
|
+
document_analyzer/analyzers/__init__.py,sha256=dQH-BhI7aFr8aCG9ivkyZKUiM9-3CdhAm9JpxahL9tw,396
|
|
6
|
+
document_analyzer/analyzers/cedula_analyzer.py,sha256=X0I6ZzkDQRAGHPj3VDvIW4EsI3-uqBB6oe0D_UZe4Fc,17532
|
|
7
|
+
document_analyzer/analyzers/document_analyzer.py,sha256=yUnoW2_xCK_eQH7zhQW56Nx4L0g4nmkgRtRql81Q43w,6632
|
|
8
|
+
document_analyzer/analyzers/passport_analyzer.py,sha256=R_UgmXLEJ4E_TySbHczESLfMo3J8Z-Jco8TFIR-5Si0,12075
|
|
9
|
+
document_analyzer/config/__init__.py,sha256=MmDUqU3h1lPboGRMnk2zGL64gayuF5jY5Y6EwuLqHHA,693
|
|
10
|
+
document_analyzer/config/constants.py,sha256=mDkmKmsiCpUDNTP2dK4bI8UVVmmCXCii4MteoG73DCs,4036
|
|
11
|
+
document_analyzer/config/logger.py,sha256=-fYcysWkZgUYNAcvh8eCLGgwiuQTWNBKzIKEAISvjQU,1361
|
|
12
|
+
document_analyzer/services/__init__.py,sha256=lHoxtSvNcaH2XOcTeZHRzkkZOoq5Q2DL_ET2SHRTq0Q,80
|
|
13
|
+
document_analyzer/services/paddleocr_service.py,sha256=o9aQQX-AuXzTpq0uLMQSvS1ggNtvNWHFHU8VBhRHiBs,3672
|
|
14
|
+
document_analyzer/utils/__init__.py,sha256=8rarlebmX3vxHhZIv837zj0Y_YvEqPShFLg6Zpmg3gM,1485
|
|
15
|
+
document_analyzer/utils/cedula_utils.py,sha256=IXfe6g_LFnDtchcDyhG1kasEknfZkDqlsc2p1Ebs8VI,5425
|
|
16
|
+
document_analyzer/utils/common_utils.py,sha256=61G_sgkk9nZ0lEpsmd9WfNHcFFDajuC_lIrIRh597qE,8028
|
|
17
|
+
document_analyzer/utils/extract_cedula_signature.py,sha256=SgoaY0pJfBYfMrVVucPRwF4T069hX7UJcRDi6PqjES8,16248
|
|
18
|
+
document_analyzer/utils/passport_language_detector.py,sha256=HbjRxV98hcyPHKx8qXRDv9D6Odg2enoUhypsW1NOXDM,9483
|
|
19
|
+
document_analyzer/utils/passport_utils.py,sha256=zURsmtx-yKZoOoxcPg1mRADAT0JZu_PPtu66oZB3crQ,7708
|
|
20
|
+
document_analyzer-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
21
|
+
document_analyzer-0.1.0.dist-info/METADATA,sha256=lnhtKjVHIAVfZtjaHbvVnqL3efRhDimK284rKbZZi_8,24242
|
|
22
|
+
document_analyzer-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
23
|
+
document_analyzer-0.1.0.dist-info/entry_points.txt,sha256=BCLfvWRfUfE6iqRyXuBZHfHAAcGuCn7jd6kqhu3sSvM,65
|
|
24
|
+
document_analyzer-0.1.0.dist-info/top_level.txt,sha256=5x8PxrvoUBIpjixDffSfsb9myWvoz8LmeNd1IUH8fJk,18
|
|
25
|
+
document_analyzer-0.1.0.dist-info/RECORD,,
|