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

2 Answers2

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
  • 30,962
  • 25
  • 85
  • 135
0

try to use builder=pyocr.builders.TextBuilder(tesseract_layout=6) instead

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 25 '23 at 13:10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34885856) – Ram Chander Aug 25 '23 at 15:03