【发布时间】: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").