繁体   English   中英

WinError 5:访问被拒绝 PyTesseract

[英]WinError 5:Access denied PyTesseract

我知道这个问题已经在这个网站上得到了回答,但是,我在互联网上查找的解决方案似乎都不起作用。 这是我尝试过的:

  • 为我的 python 文件授予所有权限
  • 更改 PATH 变量以指向我的 tesseract 文件夹
  • 以管理员身份运行 IDLE,然后从那里执行文件

这个错误现在让我很困扰,因此我无法继续前进。

如果这会有所帮助,这是我的代码:

import pytesseract
import sys
import argparse
try:
    import Image
except ImportError:
    from PIL import Image
from subprocess import check_output
pytesseract.pytesseract.tesseract_cmd = 'C:\Program Files\Tesseract-OCR'
c=pytesseract.image_to_string(Image.open('img.png'))
print(c)

追溯:

Traceback (most recent call last):
  File "C:\Users\Hp\Desktop\bot.py", line 12, in <module>
    c=pytesseract.image_to_string(Image.open('captcha.png'))
  File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
config=config)
  File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
proc = subprocess.Popen(command, stderr=subprocess.PIPE)
  File "C:\Python\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
  File "C:\Python\lib\subprocess.py", line 992, in _execute_child
startupinfo)
PermissionError: [WinError 5] Accès refusé

我怀疑一些事情,但不确定任何事情。

首先也是最明显的,Tesseract 的路径并不完整。 它应该是这样的:

tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

我相信您的路径指向目录/文件夹而不是可执行文件,但只有您可以确认。 如果这不正确,请告诉我,我也看到了一些乍一看不正确的东西,但需要更多调查。

我遇到了同样的问题,我按照 0xc0de 的说法修复了它,更改以下行:

pytesseract.pytesseract.tesseract_cmd=r"C:\MyApps\Tesseract-ocr\"

到:

pytesseract.pytesseract.tesseract_cmd="C:\\MyApps\\Tesseract-ocr\\tesseract.exe"

使用它来读取 tesseract 路径,并确保您已经安装了 Tesseract-OCR

pytesseract.pytesseract.tesseract_cmd = r'C:\\\Program Files (x86)\\\Tesseract-OCR\\\tesseract.exe'

始终使用双 \\\\ 而不是单个“\\”

您需要单独安装tesseract。 我提供了您应该安装的链接

https://github.com/UB-Mannheim/tesseract/wiki

tesseract-ocr-w32-setup-v5.0.0-alpha.20201127.exe(32 位)和 tesseract-ocr-w64-setup-v5.0.0-alpha.20201127.exe(64 位)。

根据您的系统配置选择此处。 我们大多数人都有 64 位。 所以选择那个。

非常小心地安装文件。 我建议在 c 以外的单独驱动器中执行此操作。 选择安装 tesseract.exe 文件的路径。 并将其粘贴到 pytesseract.pytesseract.tesseract_cmd

看代码...

import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'E:/OCR/tesseract_install/tesseract.exe'
img = cv2.imread('E:/OCR/example1.png')
# to see the image below codes are there
cv2.imshow('sampleimage',img)
#enter any key to destroy the image window opened due to previous line code
cv2.waitKey(0)
cv2.destroyAllWindows()
#convert image to text using tesseract
text = pytesseract.image_to_string(img)
print(text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM