Angesichts einer wichtigen Information, die als PNG-Bild angezeigt wird, musste ich nach PIL/Pytesseract greifen.
Der Code ist extrem einfach und funktioniert, wenn er als mein Benutzer ausgeführt wird. Das Bild wurde zwar geladen, wie der Druckbefehl zeigt, aber image_to_string scheint den Fehler zu erzeugen.
Code: Select all
encoded_img = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='
# Decode and open as image
img_data = base64.b64decode(encoded_img)
img_bytes = BytesIO(img_data)
img = Image.open(img_bytes)
print(img.format, img.size, img.mode)
# Use pytesseract to extract number
custom_config = r'--psm 7 -c tessedit_char_whitelist=0123456789.,'
return pytesseract.image_to_string(img, config=custom_config).strip()
Code: Select all
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 270: invalid start byteIch verwende Python3 und MacOS-Sonoma – ich bin mir nicht sicher, ob das wichtig ist.
Irgendwelche Ideen?
Mobile version