Giter VIP home page Giter VIP logo

Comments (13)

sirfz avatar sirfz commented on May 12, 2024

AnalyseLayout returns:

Page iterator or None on error or an empty page.

So you need to check if the returned value is not None before calling Orientation.

from tesserocr.

reubano avatar reubano commented on May 12, 2024

Right, it is None. But rotating an image 3 deg shouldn't cause that to happen correct?

from tesserocr.

reubano avatar reubano commented on May 12, 2024

Also, just tested via the c-api and it works fine. So not an issue with tesseract or leptonica.

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

If you look at the source code linked in my previous comment, all it does is call the respective AnalyseLayout C function and if its value is NULL returns None. Is it possible that you're getting None due to the issue in #4?

from tesserocr.

reubano avatar reubano commented on May 12, 2024

See #5 (comment)

Here's part of the working code if it helps

def get_native_orientation(tesseract, leptonica, api, path, mode=PAGE_MODE):
    tesseract.TessBaseAPISetPageSegMode(api, mode)
    pix = leptonica.pixRead(path)
    tesseract.TessBaseAPISetImage2(api, pix)

    if tesseract.TessBaseAPIRecognize(api, None):
        leptonica.pixDestroy(byref(pix))
        tesseract.TessBaseAPIDelete(api)
        raise Exception('Tesseract recognition failed')

    it = tesseract.TessBaseAPIAnalyseLayout(api)
    orientation, direction, line_order = c_int(), c_int(), c_int()
    skew = c_float()

    tesseract.TessPageIteratorOrientation(
        it, byref(orientation), byref(direction), byref(line_order),
        byref(skew))

    return orientation.value, direction.value, line_order.value, skew.value

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

Alright, the problem seems to be with the usage of PIL.Image. If you use the SetImageFile method instead of SetImage it'll work. I'm going to debug this issue and apply the appropriate fix.

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

Hey could you please test with the latest commit? It should now work as expected with PIL images.

from tesserocr.

reubano avatar reubano commented on May 12, 2024

it works, thanks! Can you let me know once you publish the new version?

from tesserocr.

reubano avatar reubano commented on May 12, 2024

Another issue tho. It works for 3deg and 4deg, but crashes when the image is rotated 5deg. And fwiw, the c-api crashes as well with Segmentation fault: 11.

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

With the 5 degrees tilt, tesseract fails to detect any text in the image (try tesseract eurotext_ang.tiff -) so this isn't related to the issue we fixed here.

Note that the tesseract executable applies a different logic to output the orientation when -psm 0 is specified. In our case we're using psm 1 and given that no text is detected, AnalyseLayout returns None.

Unfortunately, I didn't expose the DetectOS which is used in tesseract 3.04.00 to write the same logic in tesserocr. The nice thing is they made it much easier to do in tesseract 3.04.01 but implementing it will break compatibility with version 3.04.00 so I'm gonna see how to do it properly while maintaining backward compatibility (preferably with 3.02 as well).

from tesserocr.

reubano avatar reubano commented on May 12, 2024

So does that explain why running the script with psm=0 returns null
results? I wasnt aware of 'DetectOS' but it looks like it may be what i
need.

CR #6

from tesserocr.

sirfz avatar sirfz commented on May 12, 2024

Yes certainly does, seems that AnalyseLayout always returns None when psm is 0. Orientation needs to be detected differently when psm is 0, I'm going to work on it with support for 3.04.00 and the newer 3.04.01 as well, will let you know once it's ready.

from tesserocr.

redstoneleo avatar redstoneleo commented on May 12, 2024

Hello, Anyone can help with my conversion of C/C++ tesseract-ocr code to Python?
https://stackoverflow.com/questions/60166781/ctypesconvert-the-c-c-tesseract-ocr-code-to-python

from tesserocr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.