2

I keep getting an error with the following code:

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter

im = Image.open("book.jpg") # the second one
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
text = pytesseract.image_to_string(im)
print text

The error is:

File "demo2.py", line 9, in <module>
text = pytesseract.image_to_string(im)
File "/home/vagrant/src/env/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
config=config)
 File "/home/vagrant/src/env/local/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 94, in run_tesseract
stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

I'm not sure if this is an installation problem or something else. I read the answers to OSError: [Errno 2] No such file or directory using pytesser, but they didn't help me.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
KSar
  • 101
  • 1
  • 2
  • 5

1 Answers1

1

I had the same problem, but i managed to convert image to string. using apt-get should do the trick:

sudo apt-get install tesseract-ocr

and if you can't use it in a python script just do this:

from os import system

system("tesseract -l eng /image.png text.txt")
Liam
  • 6,009
  • 4
  • 39
  • 53