我尝试使用PyOCR读取图像,但出现错误提示
TypeError:需要一个类似字节的对象,而不是'PngImageFile'
我尝试使用Jpeg,但仍然出现类似
的错误TypeError:需要一个类似字节的对象,而不是'JpegImageFile'
我该怎么解决? 这是我的代码-
import sys
import pyocr.builders
import pyocr
import PIL.Image
import io
from pyocr import tesseract
#for tool in pyocr.get_available_tools():
# for lang in tool.get_available_languages():
# print("Tool {} supports language {}".format(tool, lang))
# The tools are returned in the recommended order of usage
#pyocr.get_available_tools()[0]
lang = "english"
#tool.get_available_languages()[1]
image_path = "....jpg"
im = PIL.Image.open(image_path)
PIL.Image._show(im)
im.save("img1.png","PNG")
image = PIL.Image.open("img1.png")
txt = tesseract.image_to_string(PIL.Image.open(io.BytesIO(image)), lang=lang, builder=pyocr.builders.TextBuilder())
print(txt)