4

I am having a simple code which has an image called "try.png" and I want to convert it from Image to Text using pytesseract but I am having some issues with the code.

import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r'tesseract-ocr-setup-4.00.00dev.exe'
img = cv2.imread('try.png')
img= cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
print(pytesseract.image_to_string(img))

But it's giving me an error.

Traceback (most recent call last):
  File "C:/Users/user 1/PycharmProjects/JARVIS/try.py", line 6, in <module>
    print(pytesseract.image_to_string(img))
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 356, in image_to_string
    return {
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 359, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 270, in run_and_get_output
    run_tesseract(**kwargs)
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 241, in run_tesseract
    raise e
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 238, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 740] The requested operation requires elevation

Process finished with exit code 1

Any idea on how to over come this error

harsh jain
  • 395
  • 1
  • 3
  • 11
  • 2
    Have you tried launching the code with admin rights? – dominik Jun 07 '20 at 12:56
  • Yes,but still got the same error – harsh jain Jun 07 '20 at 13:11
  • Try changing the tesseract executable to run as admin: `Right Click tesseract.exe -> Properties -> Compability -> Check Run this program as an administrator -> OK` . Also, how did you attempt to run the code with admin rights? – K41F4r Jun 08 '20 at 14:24
  • @K41F4r Wait IS it 'tesseract.exe' i wrote my path as 'tesseract-ocr-setup-4.00.00dev.exe' i just downloaded this from the website and put this as the path. but I don't have tesseract.exe I have 'tesseract-ocr-setup-4.00.00dev.exe' only. – harsh jain Jun 09 '20 at 03:59

3 Answers3

4

tesseract-ocr-setup-4.00.00dev.exe sounds like a setup exe and not the tesseract itself. Check if you have actually installed tesseract and if not launch the exe to install.

For Windows download the latest version from here: https://github.com/UB-Mannheim/tesseract/wiki

If you still get OSError: [WinError 740] The requested operation requires elevation try changing the tesseract executable to run as admin: Right Click tesseract.exe -> Properties -> Compability -> Check Run this program as an administrator -> OK .

K41F4r
  • 1,443
  • 1
  • 16
  • 36
1

I guess you have not installed tesseract on your system. Run tesseract-ocr-setup-4.00.00dev.exe to install it and make a note of the location where it is installed ($tesseractLocation) If getting the same error while installing, try running it with admin access. And Replace

pytesseract.pytesseract.tesseract_cmd=r'tesseract-ocr-setup-4.00.00dev.exe'

with

pytesseract.pytesseract.tesseract_cmd=r'$tesseractLocation'

This will resolve the issue. In the script, you have to mention the installation directory and not the setup file.

Arslan
  • 400
  • 1
  • 3
  • 10
0

Try Uncheck "Run this program as an administrator"
TRY:
Right Click tesseract.exe -> Properties -> Compability -> Uncheck Run this program as an administrator -> apply.