[Python] OpenCV produces "OCRTesseract(33): Tesseract not found" error with working Tesseract...

Discussão em 'Python' iniciado por Stack, Junho 22, 2025.

  1. Stack

    Stack Membro Participativo

    This Python 3.12.7 script with tesserocr 2.8.0 and opencv-python 4.11.0.86 works as expected:

    import cv2 as cv
    from tesserocr import PyTessBaseAPI
    from PIL import Image

    img = cv.imread('text.jpg')[:, :, 2]
    _, img = cv.threshold(img, 180, 255, cv.THRESH_BINARY_INV)
    pimg = Image.fromarray(img)
    api = PyTessBaseAPI(path='/usr/share/tesseract-ocr/4.00/tessdata')
    api.SetImage(pimg)
    print(api.GetUTF8Text())
    print(api.AllWordConfidences())


    When I try to use Tesseract directly from OpenCV with this script:

    import cv2 as cv

    img = cv.imread('text.jpg')[:, :, 2]
    _, img = cv.threshold(img, 180, 255, cv.THRESH_BINARY_INV)
    ocr = cv.text.OCRTesseract_create(datapath='/usr/share/tesseract-ocr/4.00/')
    ocr.run(img, 90)


    I'm getting this error:

    OCRTesseract(33): Tesseract not found.
    /usr/share/tesseract-ocr/4.00/


    The documentation requires datapath argument to be the name of the parent directory of tessdata ended with "/", which it is. What is the problem here?

    Continue reading...

Compartilhe esta Página