3

While I'm using below code , getting Error as "WindowsError:[Error 2] The system cannot find the file specified". Please help me to get text from image.

from pytesseract import image_to_string
from PIL import Image

print image_to_string(Image.open(r'D:\\name.jpg'),lang='eng')

ERROR:

WindowsError Traceback (most recent call last) in () 2 from PIL import Image 3 ----> 4 print image_to_string(Image.open(r'D:\name.jpg'),lang='eng')

C:\ProgramData\Anaconda2\lib\site-packages\pytesseract\pytesseract.pyc in image_to_string(image, lang, boxes, config) 120 lang=lang, 121 boxes=boxes, --> 122 config=config) 123 if status: 124 errors = get_errors(error_string)

C:\ProgramData\Anaconda2\lib\site-packages\pytesseract\pytesseract.pyc in run_tesseract(input_filename, output_filename_base, lang, boxes, config) 44 command += shlex.split(config) 45 ---> 46 proc = subprocess.Popen(command, stderr=subprocess.PIPE) 47 status = proc.wait() 48 error_string = proc.stderr.read()

C:\ProgramData\Anaconda2\lib\subprocess.pyc in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags) 388 p2cread, p2cwrite, 389 c2pread, c2pwrite, --> 390 errread, errwrite) 391 except Exception: 392 # Preserve original exception in case os.close raises.

C:\ProgramData\Anaconda2\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) 638 env, 639 cwd, --> 640 startupinfo) 641 except pywintypes.error, e: 642 # Translate pywintypes.error to WindowsError, which is

WindowsError: [Error 2] The system cannot find the file specified

1
  • to ask the obvious, are you sure there is a file in D:\name.jpg? Could you test to see if you can work with an image on your current folder instead of on `D:`?
    – Ofer Sadan
    Commented Jul 12, 2017 at 5:10

3 Answers 3

2

Install google tesseract-ocr from tesseract-ocr. The code might miss dependencies.

1
  • Having error in installation .... and also why required third party software? @Bodhi
    – siksha
    Commented Jul 12, 2017 at 5:32
1

After installation of all package and Tesseract-OCR app, you should restart your PC. I tried your code and get the same problem but after restart my PC it worked for me. Please try.

0

You dont need to give the path as raw string. Without raw string:

print image_to_string(Image.open('D:\\name.jpg'),lang='eng')

With raw string:

print image_to_string(Image.open(r'D:\name.jpg'),lang='eng')
4
  • Sorry Bodhi, I tried your code but still I'm getting same error.
    – siksha
    Commented Jul 12, 2017 at 5:07
  • How did you verify the file location ? Commented Jul 12, 2017 at 5:08
  • @Bodhi94: If you escape ` as \`, you don't need to add r
    – Rahul
    Commented Jul 12, 2017 at 5:11
  • When I'm using only "Image.open(r'D:\name.jpg')" code then my image opened successfully, but using of "image_to_string" function I am getting error.
    – siksha
    Commented Jul 12, 2017 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.