我用这个代码从图像文件中读取文本。 Reading text from image
代码如下
from PIL import Image
from pytesseract import image_to_string
image = Image.open("image.jpg",'r')
myText = image_to_string(Image.open(open('maxresdefault.jpg')),config='-psm 10')
myText = image_to_string(Image.open(open('maxresdefault.jpg')))
print(myText)
Error: UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 278: character maps to
试图从以下位置解决此错误:UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>
然后出现错误:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
根据
Image
文档(help(Image.open)
),必须以二进制模式打开图像文件:以二进制格式加载图像。在
更改以下代码为我解决了这个问题。在
希望有帮助!在
相关问题 更多 >
编程相关推荐