Issue
I Installed the 64bit version from https://github.com/UB-Mannheim/tesseract/wiki
then pip install pytesseract
cv2 didn't cause any issues
My code:
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread("test.png")
text = pytesseract.image_to_string(img)
print(text)
my code fails at line 6 with the
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\nicol\\AppData\\Local\\Temp\\tess_puh3wgus'
it seems it fails at the function
def cleanup(temp_name):
""" Tries to remove temp files by filename wildcard path. """
for filename in iglob(temp_name + '*' if temp_name else temp_name):
try:
remove(filename)
except OSError as e:
if e.errno != ENOENT:
raise e
line 131 in cleanup function at remove(filename).
It seems like it tries to remove the temp files but fails since the system denies access so-
I tried running the Spyder IDE with admin rights, I tried giving C:\Program Files\Tesseract-OCR\tesseract.exe full permissions. I ran a full anaconda update. I also tried changing the paths of TEMP and TMP system variables to places were admin rights(C:\Temp) are not required.
PermissionError: [WinError 5] Access is denied: 'C:\\Temp\\tess_hxw9iwvr.PNG'
So far I have identified the problem the pytesseract.py script creates a duplicate of the provided image, a text file with the desired output and a 0B empty file all synonymous in the format tess_[a-z0-9].extension. The problem is caused by the empty file when I try to delete it requires elevation (which I have since I am my system admin) I press the ok it briefly goes to 0% deletion and it says after access is denied because admin rights are required try again or cancel.
Solution
I guess The cleanup() function tries to remove() the file and gets access denied. Disabling the cleanup() function of the pytesseract.py covers up the problem but I managed to get the expected output with the collateral of 3 undeleted "temporary" files. Running the script again seems to replace the 0B file with a new one only if I tried to delete the file.
Answered By - Nicolai Sergeev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.