欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

tess4j datapath set windows

程序员文章站 2022-03-05 10:25:23
...

在网上各种百度,谷歌都没有找到想要的结果,真是气死了。还得自己一点一点找。

dependency

SOFTWARE REQUIREMENTS

Java Runtime EnvironmentJNA, and JAI-ImageIO are required. Apache Maven and JUnit are used for program building and unit testing. The Tesseract DLLs were built with VS2019 (v142) and therefore depend on the Visual C++ 2019 Redistributable Packages.

https://aka.ms/vs/16/release/VC_redist.x64.exe

1.引入maven

 <dependency>
            <groupId>net.sourceforge.tess4j</groupId>
            <artifactId>tess4j</artifactId>
            <version>${tess4j.version}</version>
 </dependency>

2. 直接写代码

package net.sourceforge.tess4j.example;

import java.io.File;
import net.sourceforge.tess4j.*;

public class TesseractExample {
    public static void main(String[] args) {
        // ImageIO.scanForPlugins(); // for server environment
        File imageFile = new File("eurotext.tif");
        ITesseract instance = new Tesseract(); // JNA Interface Mapping
        // ITesseract instance = new Tesseract1(); // JNA Direct Mapping
        // File tessDataFolder = LoadLibs.extractTessResources("tessdata"); // Maven build only; only English data bundled,这部分的dataPath是直接拿的jar包部分的训练数据
        // instance.setDatapath(tessDataFolder.getPath());
       

        try {
            String result = instance.doOCR(imageFile);
            System.out.println(result);
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
    }
}

如果需要自己自定义datapath,直接再代码里修改,注意结尾要有\\

 instance.setDatapath("C:\\Users\\Administrator\\IdeaProjects\\tessdata\\");

ps,详情可以 去看解压jar包后的readme.html

tess4j datapath set windows

相关标签: 笔记