【问题标题】:Pytesseract: UnicodeDecodeError: 'charmap' codec can't decode bytePytesseract:UnicodeDecodeError:'charmap'编解码器无法解码字节
【发布时间】:2015-10-03 21:24:06
【问题描述】:

我正在使用 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>

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

【问题讨论】:

标签: python-3.x tesseract python-unicode python-tesseract


【解决方案1】:

使用Unidecode

from unidecode import unidecode
import pytesseract

strs = pytesseract.image_to_string(Image.open('binarized_image.png'))
strs = unidecode(strs)
print (strs)

【讨论】:

    【解决方案2】:

    确保您使用的是正确的解码选项。
    https://docs.python.org/3/library/codecs.html#standard-encodings

    str.decode('utf-8')
    bytes.decode('cp950') 繁体中文等

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      相关资源
      最近更新 更多