question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

image_to_data returns different results than image_to_string

See original GitHub issue

I use image_to_string for single digits but additionally I want to obtain the confidence value. Therefore I replaced it with image_to_data like this:

ocrResult = pytesseract.image_to_data(digitBinary, config='-psm 10 -c tessedit_char_whitelist=0123456789', output_type="dict")
digitasNumber = ocrResult["text"][0]

With image_to_string the results are reasonably good. With image_to_data every text dict entry is empty but for one case, where it returns two digits. the empty digits have conf -1 and the digit where text is filled the conf is 6.

I don’t think that this is intended behavior.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BSVoglercommented, Jul 15, 2018

The default value is not the real problem here. The problem is that the tsv config is apparently loaded after the config is applied (see my use case in the first post) and overwriting the value. I tried to fix the code by myself but I didn’t manage to make it work so far.

Internally it is currently called like this

"tesseract" + config + image +" tsv"

but it should be

"tesseract " + config + " -c tessedit_create_tsv=1 "+ image
0reactions
mbdilavercommented, Jun 9, 2020

CLI prints the same output of image_to_string() to a .txt file and image_to_data() to a .tsv file when I gave parameter -c tessedit_create_tsv=1.

The problem is image_to_string() output is really good, but it doesn’t have text coordinates. image_to_data() output has all of the additional data but it shows each word in a seperate field.

Let’s say I have an image with Text: Hello World! text on it. image_to_string() returns Text: Hello World! (or something similar to it) where image_to_data() returns ["Text:", "Hello", "World!"] (basically) and loses spaces between words. I guess I need to concatnate these words manually 😞 This is the difference I’m talking about. The result is same in terms of letters.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tesseract ocr text: output difference between image_to_string ...
I am doing some OCR using tesseract to recognition text and numbers on a document. I used pytesseract as my python wrapper.
Read more >
Pytesseract Behaving Differently In Windows Vs. Linux
Tesseract is an optical character recognition engine for various ... Linux Mac OSX and Windows.. imagetodata returns different results than imagetostring.
Read more >
Tesseract OCR in Python with Pytesseract & OpenCV
In OCR software, it's main aim to identify and capture all the unique words using different languages from written text characters. For almost ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found