【问题标题】:How to use user-words in Tesseract (Java)?如何在 Tesseract (Java) 中使用用户词?
【发布时间】:2015-03-27 09:32:29
【问题描述】:

我将 Tesseract 用于 OCR 目的,并且我在“fin.user-words”中添加了一些额外的单词(我想避免创建新单词列表并替换 tessdata/ fin.word-dawg)。 现在,我在命令提示符下成功了:

>tesseract image.png result -l fin TestConfig

其中 TestConfig(位于 .../tessdata/configs 下的 Tesseract 配置文件)抑制系统字典并强制 Tesseract 加载我的话:

load_system_dawg F
load_freq_dawg F
user_words_suffix user-words

参考:http://tesseract-ocr.googlecode.com/svn/trunk/doc/tesseract.1.html#_config_files_and_augmenting_with_user_data

我正在尝试在 Java 中复制上述命令行过程,但似乎 Tesseract 忽略了配置选项。 这是我正在使用的 Java 代码的一部分:

public static TestTesseract(BufferedImage image) {
        Tesseract instance = Tesseract.getInstance();
        instance.setLanguage("fin");
        instance.setTessVariable("load_system_dawg", "F");
        instance.setTessVariable("load_freq_dawg", "F");
        instance.setTessVariable("user_words_suffix", "user-words");
        try {
            String result = instance.doOCR(image);
            System.out.println(result);         
        } catch (TesseractException e) {
            System.err.println(e.getMessage());
        }
}

以下是我能找到的最接近我的问题;但是,我可以找到 setConfigs 方法:

instance.setConfigs(Arrays.asList("bazaar");

Forcing Tesseract to match pattern (four digits in a row)

【问题讨论】:

    标签: java ocr tesseract tess4j config-spec


    【解决方案1】:

    setConfig 方法是自 Tess4J v1.4 以来的新方法(请参阅doc)。

    instance.setConfigs(Arrays.asList("TestConfig");
    

    【讨论】:

    • 谢谢@nguyenq。更新 tp 1.4 后,我无法再使用 Tesseract:Exception in thread "Run$_main" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils at net.sourceforge.tess4j.util.LoadLibs.copyJarResourceToDirectory(Unknown Source) at net.sourceforge.tess4j.util.LoadLibs.extractTessResources(Unknown Source) at net.sourceforge.tess4j.util.LoadLibs.<clinit>(Unknown Source) at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source) at net.sourceforge.tess4j.Tesseract.init(Unknown Source) at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    • at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) at TestTesseract.TestTesseract(TestTesseract.java:302) Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 10 more
    • 啊,我想我明白了。基本上我需要 commons IO 才能运行 v1.4
    • 再次感谢@nguyenq。
    猜你喜欢
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2011-12-04
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 2016-08-15
    相关资源
    最近更新 更多