Search code examples
pythontesseractpython-tesseract

Get orientation pytesseract Python3


I want to get the orientation of a scanned document. I saw this post Pytesseract OCR multiple config options and I tried to use --psm 0 to get the orientation.

target = pytesseract.image_to_string(text, lang='eng', boxes=False, \
config='--psm 0 tessedit_char_whitelist=0123456789abcdefghijklmnopqrstuvwxyz')

But I get an error:

FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/jy/np7p4twj4bx_k396hyc_bnxw0000gn/T/tess_dzgtpadd_out.txt'

Solution

  • I found another way to get the orientation using pytesseract:

    print(pytesseract.image_to_osd(Image.open(file_name)))
    

    This is the output:

    Page number: 0
    Orientation in degrees: 270
    Rotate: 90
    Orientation confidence: 21.27
    Script: Latin
    Script confidence: 4.14