Search code examples
pythonpython-tesseract

Permission denied when reading a image-text in pytesseract


import cv2
import pytesseract as pt

pt.pytesseract.tesseract_cmd = r"tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe"

image = cv2.imread("NormalText.jpg")

text = pt.image_to_string(image)
print(text)

I am trying to convert this image to a string, but this error showed up:

Traceback (most recent call last):
  File "PythonFile/Image-Text.py", line 8, in <module>
    text = pt.image_to_string(image)
  File "/opt/anaconda3/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 370, in image_to_string
    return {
  File "/opt/anaconda3/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 373, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "/opt/anaconda3/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 282, in run_and_get_output
    run_tesseract(**kwargs)
  File "/opt/anaconda3/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 253, in run_tesseract
    raise e
  File "/opt/anaconda3/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 250, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "/opt/anaconda3/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/anaconda3/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe'

What should I do? please let me know, it would be greatly appreciate it.


Solution

  • Try this

    import pytesseract as ts
    from PIL import Image
    
    img=Image.open("NormalText.jpg")
    text=ts.image_to_string(img)
    print(text)
    

    It works for me