我已经使用此代码从图像文件中读取文本。从图像读取文字
代码如下
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)
错误:unicodedecodeerror:'charmap'编解码器无法在位置278中解码字节0x81:字符映射到
试图从以下内容求解此错误:unicodeDecodeError:'Charmap'编解码器无法在位置y:字符映射到< unddectined>
中解码字节x。然后出现错误:
unicodedecodeerror:'utf-8'编解码器无法在位置0 x byte 0xff解码:无效启动字节
根据Image
文档(help(Image.open)
(,必须在二进制模式下打开图像文件:
open('maxresdefault.jpg', 'rb')
以二进制格式加载图像。
更改以下代码解决了我的问题。
import PIL.Image
pil_image = PIL.Image.open(image_path, "rb")
希望它有帮助!