Pytesseract:UnicodeDecodeError:'charmap' 编解码器无法解码字节 [英] Pytesseract: UnicodeDecodeError: 'charmap' codec can't decode byte

查看:758
本文介绍了Pytesseract:UnicodeDecodeError:'charmap' 编解码器无法解码字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running a large number of OCRs on screenshots with Pytesseract. This is working well in most cases, but a small number is causing this error:

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.任何关于如何防止此错误发生的建议(不仅仅是尝试/除外)都会非常有帮助.

I'm using Python 3.4. Any suggestions how I can prevent this error from happening (other than just a try/except) would be very helpful.

推荐答案

使用 Unidecode

from unidecode import unidecode
import pytesseract

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

这篇关于Pytesseract:UnicodeDecodeError:'charmap' 编解码器无法解码字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆