cha*_*dra 1 tesseract windowserror python-2.7 python-tesseract
我尝试使用 Pytesseract 从图像中读取文本。运行以下脚本时收到拒绝访问消息。
from PIL import Image
import pytesseract
import cv2
import os
filename=r'C:\Users\ychandra\Documents\teaching-text-structure-3-728.jpg'
pytesseract.pytesseract.tesseract_cmd = r'C:\Python27\Lib\site-packages\pytesseract'
image=cv2.imread(filename)
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray=cv2.threshold(gray,0,255,cv2.THRESH_BINARY|cv2.THRESH_OTSU)[1]
gray=cv2.medianBlur(gray,3)
filename='{}.png'.format(os.getpid())
cv2.imwrite(filename,gray)
text=pytesseract.image_to_string(Image.open(filename))
print text
cv2.imshow("image",image)
cv2.imshow("res",gray)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时,我遇到了错误
Traceback (most recent call last):
File "F:\opencv\New_folder_3\text_from_image.py", line 17, in <module>
text=pytesseract.image_to_string(Image.open(filename))
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 5] Access is denied
Run Code Online (Sandbox Code Playgroud)
除了pytesseract.pytesseract.tesseract_cmd. 该tesseract_cmd应设置为tesseract executable file安装在您的机器。
这是它的示例用法。
pytesseract.pytesseract.tesseract_cmd = "C:/Program Files/Tesseract 4.0.0/tesseract.exe"
Run Code Online (Sandbox Code Playgroud)
tesseract_cmd如果PATH您的 Windows PC 中没有正确的搜索设置,则这是必需的。
希望这有帮助。
更新:
tesseract在使用模块从 Python 在 Windows shell 中运行 tesseract之前pytesseract,您需要将二进制文件安装到您的 PC 中subprocess。
单击此Tesseract 4.00 alpha下载 64 位 Windows 版本并安装它。然后分别设置PATH和TESSDATA_PREFIX指向您的tesseract.exe和~\tessdata目录。

如果您需要任何其他语言trained data file,可以在[此处] 获取。
如果~\tessdata在您的 Windows 中找不到该目录,您可以手动创建它并将至少一个traineddata文件复制到那里,例如eng.traineddata英语。
如果tesseract正在工作,它将在您键入tesseract -v命令提示符时返回版本信息,如下所示。

| 归档时间: |
|
| 查看次数: |
4457 次 |
| 最近记录: |