在Windows CMD上尝试Tesseract

时间:2017-07-19 09:34:01

标签: python tesseract pytesser

我在使用带有pytesseract Python包装器的Tesseract-OCR时遇到了麻烦。 我认为问题可能来自Tesseract本身,而不是来自包装器。 所以我在CMD中尝试了Tesseract:

C:\Users\Thomas\Desktop>tesseract.exe 'blabla.jpg' 'out.txt'

它返回以下几行:

Tesseract Open Source OCR Engine v3.05.01 with Leptonica
Error in fopenReadStream: file not found
Error in findFileFormat: image file not found
Error during processing.

我已完成以下操作以安装Tesseract:

顺便说一句,我在运行Python代码时遇到的问题是:

from PIL import Image
import pytesseract
text = pytesseract.image_to_string(Image.open('blabla.jpg')
print(text)

是:

Traceback (most recent call last):

  File "<ipython-input-1-01e77f902509>", line 1, in <module>
runfile('D:/anaconda/projects/OCR/ocr.py', wdir='D:/anaconda/projects/OCR')

  File "D:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)

  File "D:\anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/anaconda/projects/OCR/ocr.py", line 48, in <module>
text = pytesseract.image_to_string(a)

  File "D:\anaconda\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)

  File "D:\anaconda\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)

  File "D:\anaconda\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)

  File "D:\anaconda\lib\subprocess.py", line 990, in _execute_child
startupinfo)

PermissionError: [WinError 5] Access refused

以管理员身份运行代码并不能解决问题

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

首先,要验证tesseract是否有效Windows command prompt,如果图片和/或输出文件名由{{1}组成,请使用" "代替' ' }。否则不需要引号。

space

其次,使用完整文件路径来指定图像文件。如,

C:\Users\Thomas\Desktop>tesseract.exe blabla.jpg out.txt

请注意,正斜杠pytesseract.pytesseract.tesseract_cmd = 'C:/path/to/tesseract.exe' text = pytesseract.image_to_string(Image.open('D:/path/to/blabla.jpg')) 用于指定任何文件路径而不是反斜杠/,或者您使用双反斜杠\,例如\\

希望得到这个帮助。