pytesseract image_to_string没有拉动字符串,但没有错误

时间:2018-04-26 17:13:01

标签: python-3.x image image-processing python-imaging-library python-tesseract

我正在使用pytesseract包中的image_to_string函数将单个图片文件的多个部分转换为字符串。除此图像外,所有部件均正常工作:

enter image description here

以下是我用来转换它的脚本:

from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'

im = Image.open('image.png')
text = pytesseract.image_to_string(im)
print(text)

给出了输出:

  

- \ - \ - \ N - \ - \ - \ - \ - \ n

我尝试将图像分解成更小的部分,并将图像作为jpg和png处理。如何让它输出图像中的值?

1 个答案:

答案 0 :(得分:1)

使用其他页面细分代替默认的页面细分似乎可行。

text = pytesseract.image_to_string(im,config ='--psm 6'))

根据tesseract Wiki,选项6假定单个统一的文本块。我尝试了其他选择,但只有这个可行。 要检查其他页面分割方法,请阅读tesseract Wiki,了解如何提高图像质量。