3

I am trying to pass configuration arguments to pytesseract's image_to_string function.

The code I am running is the following.

filename = 'address1_203.png'
img = Image.open(cam_img+filename)

ocr_out = ocr.image_to_string(img, lang='por', config='-psm 7')

print(ocr_out)

and the error message is

TypeError: image_to_string() got an unexpected keyword argument 'config'

There is another similar question in stackoverflow, but I don't think it solves the problem I am having.

I installed pytesseract through conda with conda install -c auto pytesseract

The code works if I remove the config parameter

P.S.: this is the first question I am posting, please give me feedback if I've done it properly or not. thanks =)

1 Answers1

0

It's my first time using tesseract, maybe you should try this notation.

image_url = 'test2.png'
custom_config = r'-l por --psm 7'
print(pytesseract.image_to_string(image_url, config=custom_config))

It is important to know that the environment (Windows, linux etc) should have the installation of tesseract in my case I use ubuntu and I installed on these way

sudo apt install tesseract-ocr
sudo apt-get install tesseract-ocr-por -y

and then you can check the languages installed

tesseract --list-langs

https://github.com/NanoNets/ocr-with-tesseract/blob/master/tesseract-tutorial.ipynb

Dharman
  • 26,923
  • 21
  • 73
  • 125