Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Potential bug: output of Tesseract (C-API) and Tesseract (sh) is different #50

Open
mathiasimmer opened this issue Dec 4, 2016 · 4 comments

Comments

@mathiasimmer
Copy link

I got this simple example:

from PIL import Image
from pyocr import pyocr

py_img = Image.open('text.png')
for tool in pyocr.get_available_tools():
    print("Using pyocr tool '%s'" % (tool.get_name()))
    print(tool.image_to_string(py_img))

Where text.png is:
text

As this is a fairly simple case I would have expected the outcome to be the same however the outcome is:

Using pyocr tool 'Tesseract (C-API)'
Empty page!!

Using pyocr tool 'Tesseract (sh)'
3/2

Is this a bug or are the two tools configured differently by default?
I know the Tesseract (C-API) works properly on my computer as I have used it successfully with similar but different input, however in this very particular case, it fails.

@mathiasimmer
Copy link
Author

Maybe I should add an example where the output is there same:
text2
gives:

Using pyocr tool 'Tesseract (C-API)'
l/Z
Using pyocr tool 'Tesseract (sh)'
l/Z

Which was more like what I would've expected. Ignore that the text is wrong; I know how to fix that, but at least the output is consistent.

@jflesch
Copy link
Member

jflesch commented Dec 4, 2016

I observed a similar problems when making the tests. The output of libtesseract and tesseract (sh) are slightly different. Quite frankly I'm not sure where this difference comes from.

Currently, my main theory is that it comes from the way images are read:

  • with libtesseract, the input image is loaded by PIllow, turned into a raw image and then passed directly to libtesseract.
  • With tesseract (sh), Pillow read the image, save it back as a .bmp, then tesseract loads this .bmp using libleptonica and pass it raw to Tesseract.
    Maybe somewhere there is a slight difference in the way images are encoded / decoded that makes the OCR reacts differently.

@amitdo
Copy link

amitdo commented Dec 31, 2017

I don't know if it's related to this issue, but one difference between tesseract and libtesseract is the default psm. The default psm in tesseract is '3', while in libtesseract it's '6'.

https://github.com/tesseract-ocr/tesseract/blob/cdc35338c53a1af1fcb95473445f2aabfdb3f6d1/api/tesseractmain.cpp#L222

@jflesch
Copy link
Member

jflesch commented Jan 1, 2018

Good point. It might explain the differences. I'll have a look later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants