Passport parser in progress

This commit is contained in:
Nitwix
2025-04-12 20:12:14 +02:00
9 changed files with 153 additions and 21 deletions

View File

@ -1,8 +1,10 @@
import base64
import io
from tempfile import NamedTemporaryFile
from PIL import Image
import pytesseract
from passporteye import read_mrz
import json
def process_passport(passport_b64: str) -> str:
"""
@ -14,6 +16,12 @@ def process_passport(passport_b64: str) -> str:
:return: Texte extrait de l'image.
"""
image_bytes = base64.b64decode(passport_b64)
image = Image.open(io.BytesIO(image_bytes))
text = pytesseract.image_to_string(image, lang='eng')
# image = Image.open(io.BytesIO(image_bytes))
# text = pytesseract.image_to_string(image, lang='eng')
with NamedTemporaryFile(mode="wb") as tmp_img:
tmp_img.write(image_bytes)
with open(tmp_img.name, "rb") as read_img:
text = read_mrz(read_img)
# text = json.dumps(text)
# TODO CONTINUE
return text