python-3.xwindowspython-tesseract

How do I install a new language pack for Tesseract on Windows


I have installed the pytesseract module in my venv and want to extract text from a German image.

Eith executing this script from pytesseract and setting the language to German

import cv2

import pytesseract


try:
    from PIL import Image
except ImportError:
    import Image

print(pytesseract.image_to_string(Image.open('test.jpg')))

print(pytesseract.image_to_string(Image.open('test.jpg'), lang='ger'))

which gives me

raise TesseractError(proc.returncode, get_errors(error_string))
pytesseract.pytesseract.TesseractError: (1, 'Tesseract Open Source OCR Engine v3.05.00dev with Leptonica
 Error opening data file C:\\Program Files (x86)\\Tesseract-OCR/tessdata/ger.traineddata
 Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language \'ger\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')

I have found the language data on [tessdoc/Data-Files] (https://github.com/tesseract-ocr/tessdoc/blob/master/Data-Files.md)

So far I only found a guide for Linux How do I install a new language pack for Tesseract on 16.04

Where do I need to move the language files in my pyteseract sitepackage to get the script working?


Solution

  • found a guide to do this on a german site Python Texterkennung: Bild zu Text mit PyTesseract in Windows