Passport parser in progress
This commit is contained in:
@ -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
|
Reference in New Issue
Block a user