【问题标题】:pytesseract don't work with one digit imagepytesseract 不适用于一位数字图像
【发布时间】:2015-07-26 23:59:09
【问题描述】:

我有使用 pytesseract 的代码并且工作完美,只有当我尝试识别的图像是 0 到 9 时才不起作用。如果图像只有一位数字,则不给出任何结果。

这是我正在处理的图片示例 https://drive.google.com/folderview?id=0B68PDhV5SW8BdFdWYVRwODBVZk0&usp=sharing

这是我正在使用的代码

    import pytesseract
    varnum= pytesseract.image_to_string(Image.open('images/table/img.jpg'))
    varnum = float(varnum)
    print varnum    

谢谢!!!!

使用此代码,我可以读取所有数字

import pytesseract


start_time = time.clock()
y = pytesseract.image_to_string(Image.open('images/table/1.jpg'),config='-psm 10000')
x = pytesseract.image_to_string(Image.open('images/table/1.jpg'),config='-psm 10000')

print y
print x

y = pytesseract.image_to_string(Image.open('images/table/68.5.jpg'),config='-psm 10000')
x = pytesseract.image_to_string(Image.open('images/table/68.5.jpg'),config='-psm 10000')

print y
print x

print time.clock() - start_time, "seconds" 

结果

>>> 
1
1
68.5
68.5
0.485644155358 seconds
>>> 

【问题讨论】:

  • 你可以试试像 - varnum= pytesseract.image_to_string(Image.open('images/table/img.jpg'),config="-psm 1") 吗?
  • 或者 - varnum= pytesseract.image_to_string(Image.open('images/table/img.jpg'),config="-psm 10") .

标签: python ocr


【解决方案1】:

您需要设置页面分段模式才能读取单个字符/数字。

tesseract-ocr manual(这是pytesseract内部使用的),您可以使用-设置页面分割模式-

-psm N

将 Tesseract 设置为仅运行布局分析的子集并假设 某种形式的图像。 N 的选项是:

10 = 将图像视为单个字符。

所以您应该将-psm 选项设置为 10。示例 -

varnum= pytesseract.image_to_string(Image.open('images/table/img.jpg'),config='-psm 10')

【讨论】:

  • 对于其他人,请注意配置应该是两个破折号:config='--psm 10'
猜你喜欢
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 2021-03-12
  • 2023-02-07
  • 1970-01-01
  • 2016-09-24
  • 2020-10-28
  • 1970-01-01
相关资源
最近更新 更多