3

我试图让 Tesseract(使用 Tess4J 包装器)仅匹配特定模式。模式是连续四位数,我认为应该是\d\d\d\d。这是我正在喂 tesseract 的图像的一个非常小的子集(平面图受到限制,所以我很谨慎地发布更多内容): http: //mike724.com/view/a06771

我正在使用以下java代码:

    File imageFile = new File("/<redacted>/file.pdf");

    Tesseract instance = Tesseract.getInstance();
    instance.setTessVariable("load_system_dawg", "F");
    instance.setTessVariable("load_freq_dawg", "F");
    instance.setTessVariable("user_words_suffix", "");
    instance.setTessVariable("user_patterns_suffix", "\\d\\d\\d\\d");

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

我遇到的问题是 tesseract 似乎不尊重这些配置选项,我仍然在结果中得到文本/单词。我希望只得到房间号(例如 2950)。

4

2 回答 2

2

您没有正确配置它。

user_patterns_suffix 表示包含您的模式的文本文件的文件扩展名,例如

user_patterns_suffix pats

意味着您需要在 tesseract tessdata 文件夹中放置一个文件

tessdata/eng.pats

...假设 eng 是您使用的语言。

在这里查看更多:

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

我确实记得用户模式在模式之前可能不会短于 6 个固定字符,因此您可能无法在任何情况下完成此操作 - 但请先尝试正确的配置。

于 2015-01-14T16:24:46.393 回答
0

它们看起来像仅初始化参数;因此,它们需要在配置文件中,例如,命名bazaar放置在configs文件夹下,以传递给setConfigs方法。

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

参考资料:
https ://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc
https://github.com/tesseract-ocr/tesseract/wiki/ControlParams
http://tess4j。 sourceforge.net/docs/docs-1.4/

于 2015-01-19T03:40:55.397 回答