错误声明所需的字节类型对象,即使在我使用PIL和pyocr在Tesseract中拥有io.ByteIO之后

时间:2019-01-31 04:16:34

标签: python-3.x python-imaging-library ocr tesseract

我尝试使用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)

0 个答案:

没有答案