Tess4j doesn't use it's tessdata folder

前端 未结 4 1608
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 01:54

I am using tess4j, the java wrapper of Tesseract. I also have the normal Tesseract installed. I am not exactly sure how tess4j is meant to work, but since it comes with a te

相关标签:
4条回答
  • 2020-12-16 02:22

    Maybe you haven't the tessdata folder in your main project folder. This folder has all tesseract supported language (it contains files with .traineddata, .bigrams, .fold, .lm, .nn, .params, .size and .word-freq extensions) If you don't have it, follow these steps:

    1. Download tessdata-master folder from github.com/tesseract-ocr/tessdata (from download ZIP button)
    2. Unzip the content of tessdata-master.zip file in your main project folder
    3. Rename tessdata-master to tessdata
    4. Run your java project and test if it work. At least this works for me.
    0 讨论(0)
  • 2020-12-16 02:38

    For those that use maven and don't like to use global variables, this works for me:

    File imageFile = new File("C:\\random.png");
    Tesseract instance = Tesseract.getInstance();
    
    //In case you don't have your own tessdata, let it also be extracted for you
    File tessDataFolder = LoadLibs.extractTessResources("tessdata");
    
    //Set the tessdata path
    instance.setDatapath(tessDataFolder.getAbsolutePath());
    
    try {
        String result = instance.doOCR(imageFile);
        System.out.println(result);
    } catch (TesseractException e) {
        System.err.println(e.getMessage());
    }
    

    found here, tested with maven -> net.sourceforge.tess4j:tess4j:3.4.1, also the link use 1.4.1 jar

    0 讨论(0)
  • 2020-12-16 02:41

    TESSDATA_PREFIX environment variable, if defined, will overrule everything, including that is set by init or setDatapath; but that may change in the near future when an application can specify where its tessdata folder is.

    http://code.google.com/p/tesseract-ocr/issues/detail?id=938
    https://groups.google.com/forum/#!topic/tesseract-ocr/bkJwI8WmxSw

    0 讨论(0)
  • 2020-12-16 02:48

    Let your TESSDATA_PREFIX environment variable point to the tessdata folder of your Tess4j.

    Usually you set up these variable during an installation on the system, but you maybe find a solution here: How do I set environment variables from Java?

    You have to do it on the system which runs your app because the tessdata .dlls depend on this enviroment variable.

    0 讨论(0)
提交回复
热议问题