Tess4j doesn't use it's tessdata folder

前端 未结 4 1607
佛祖请我去吃肉
佛祖请我去吃肉 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: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

提交回复
热议问题