Fix passport parser
This commit is contained in:
@ -16,12 +16,20 @@ def process_passport(passport_b64: str) -> str:
|
|||||||
:return: Texte extrait de l'image.
|
:return: Texte extrait de l'image.
|
||||||
"""
|
"""
|
||||||
image_bytes = base64.b64decode(passport_b64)
|
image_bytes = base64.b64decode(passport_b64)
|
||||||
# image = Image.open(io.BytesIO(image_bytes))
|
|
||||||
# text = pytesseract.image_to_string(image, lang='eng')
|
|
||||||
with NamedTemporaryFile(mode="wb") as tmp_img:
|
with NamedTemporaryFile(mode="wb") as tmp_img:
|
||||||
tmp_img.write(image_bytes)
|
tmp_img.write(image_bytes)
|
||||||
with open(tmp_img.name, "rb") as read_img:
|
with open(tmp_img.name, "rb") as read_img:
|
||||||
text = read_mrz(read_img)
|
mrz_obj = read_mrz(read_img)
|
||||||
# text = json.dumps(text)
|
|
||||||
# TODO CONTINUE
|
image = Image.open(io.BytesIO(image_bytes))
|
||||||
return text
|
tesseract_text = pytesseract.image_to_string(image, lang='eng')
|
||||||
|
out_dict = {
|
||||||
|
"country": mrz_obj.country,
|
||||||
|
"names": mrz_obj.names,
|
||||||
|
"number": mrz_obj.number,
|
||||||
|
"surname": mrz_obj.surname,
|
||||||
|
"mrz": mrz_obj.aux["text"],
|
||||||
|
"raw": tesseract_text
|
||||||
|
}
|
||||||
|
out = json.dumps(out_dict)
|
||||||
|
return out
|
Reference in New Issue
Block a user