Pytesseract:UnicodeDecodeError:“charmap”编解码器无法解码字节

Nic*_*ick 5 tesseract python-3.x python-unicode python-tesseract

我使用 Pytesseract 对屏幕截图运行大量 OCR。这在大多数情况下运行良好,但少数情况会导致此错误:

pytesseract.image_to_string(image,None, False, "-psm 6")
Pytesseract: UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud)

我正在使用Python 3.4。任何如何防止此错误发生的建议(不仅仅是尝试/例外)都会非常有帮助。

Sre*_*A R 3

使用统一码

from unidecode import unidecode
import pytesseract

strs = pytesseract.image_to_string(Image.open('binarized_image.png'))
strs = unidecode(strs)
print (strs)
Run Code Online (Sandbox Code Playgroud)