仅将用户词添加到 Tesseract

Adding only user-words to Tesseract

我在 android 应用程序中使用 Tesseract。我定义了我的 "user-words" 文件,并为 ocr 添加了粗体行以考虑用户词文件。

String language = "deu";
datapath = getFilesDir()+ "/tesseract/";
Tess = new TessBaseAPI();

checkFile(new File(datapath + "tessdata/"));
**Tess.setVariable("user_words_suffix","deu.user-words");**
Tess.init(datapath, language);

我没有定义用户模式文件,因为我的图像中没有任何特定模式。我只是将due.user-words的UTF-8 txt文件复制到tessdata文件夹中。这足以进行 ocr 配置吗?或者我应该解压缩 due_traindata 并将此文件添加到 due_traindata 然后打包吗?如果是的话,你能给我一些关于如何做到这一点的提示吗?

您无需在代码中指定语言前缀:

Tess.setVariable("user_words_suffix", "user-words");

确保文件的前缀与指定的语言代码相匹配 -- 即 deu.user-words.

https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc https://github.com/tesseract-ocr/tesseract/wiki/ControlParams