pytesseract不适用于一位数的图像

Xav*_*ina 7 python ocr

我有使用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    
Run Code Online (Sandbox Code Playgroud)

谢谢!!!!

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

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" 
Run Code Online (Sandbox Code Playgroud)

结果

>>> 
1
1
68.5
68.5
0.485644155358 seconds
>>> 
Run Code Online (Sandbox Code Playgroud)

Ana*_*mar 6

您需要将页面分割模式设置为能够读取单个字符/数字.

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

-psm N.

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

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

所以你应该把-psm选项设置为10.示例 -

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

  • 对于其他人,请注意配置应该有两个破折号:`config='--psm 10'` (3认同)