Search code examples
pythonpython-2.7numpypytesser

pytesseract shows " 'str' object has no attribute 'save' " error


when i run the following code for pytesseract

>>> import pytesseract
>>> import Image
>>> print pytesseract.image_to_string("plate.png")

it shows the below error

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    print pytesseract.image_to_string("plate.png")
  File "/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.py", line 137, in image_to_string
    image.save(input_file_name)
AttributeError: 'str' object has no attribute 'save'

what does this error mean? How can i correct this?

thanks in advance


Solution

  • Pass an image object instead of file path (string):

    import pytesseract
    import Image
    
    im = Image.open("plate.png")
    print pytesseract.image_to_string(im)