siksha
siksha

Reputation: 126

unable to get text from image using pytesseract

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

Upvotes: 3

Views: 1168

Answers (3)

cSharma
cSharma

Reputation: 645

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.

Upvotes: 1

Vibhutha Kumarage
Vibhutha Kumarage

Reputation: 1399

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

Upvotes: 2

Vibhutha Kumarage
Vibhutha Kumarage

Reputation: 1399

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')

Upvotes: 0

Related Questions