sirfz / tesserocr

A Python wrapper for the tesseract-ocr API
MIT License
2.02k stars 254 forks source link

Tesserocr gives incorrect orientation results with PSM.OSD_ONLY (and different results to command line version) #199

Closed dannyfriar closed 4 years ago

dannyfriar commented 5 years ago

The following code snippet from the pypi project gives an incorrect result after rotating the eurotext.tif image (from tests directory of repo). E.g. after rotating the image by 180 degrees:

from tesserocr import PyTessBaseAPI, PSM

with PyTessBaseAPI(psm=PSM.OSD_ONLY) as api:
    api.SetImageFile("/usr/src/tesseract/testing/eurotext.tif")

    os = api.DetectOS()
    print("Orientation: {orientation}\nOrientation confidence: {oconfidence}\n"
          "Script: {script}\nScript confidence: {sconfidence}".format(**os))

Result:

Orientation: 0
Orientation confidence: 0.0
Script: 2
Script confidence: nan

Running tesseract /usr/src/tesseract/testing/eurotext.tif- --psm 0 gives:

Orientation in degrees: 180
Rotate: 180
Orientation confidence: 28.28
Script: Latin
Script confidence: 6.05

Tesserocr: 2.4.1 OS: macOS 10.14.3

tesseract 4.1.0 leptonica-1.78.0 libgif 5.1.4 : libjpeg 9c : libpng 1.6.37 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.3 : libopenjp2 2.3.1

bertsky commented 4 years ago

You have to load the osd model, otherwise OSD won't work. Also, you might need to set oem. Try:

from tesserocr import OEM
with PyTessBaseAPI(
    psm=PSM.OSD_ONLY,
    lang="osd",
    oem=OEM.TESSERACT_LSTM_COMBINED
) as api: