簡體   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