在tesseract C API中禁用字典辅助的OCR

在tesseract C API中禁用字典辅助的OCR

我有一个应用程序,其中使用tesseract API对技术数据表进行OCR.我像这样初始化它:

 

 

tesseract::TessBaseAPI tess;
tess.Init(NULL, "eng", tesseract::OEM_TESSERACT_ONLY);

但是,即使使用了这样的自定义白名单

 

tess.SetVariable("tessedit_char_blacklist", "");
tess.SetVariable("tessedit_char_whitelist", myWhitelist);

某些数据表条目被错误识别,例如PA3被识别为FAB.

如何禁用字典辅助的OCR,即.为了不影响其他工具,我不想在可能的情况下修改全局配置文件.

注意:这不是this previous question的副本,因为当我明确要求tesseract API时,所述问题明确要求使用命令行工具.

最佳答案
你可以通过以下方式完成

 

 

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
if (api->Init(NULL, "eng"))
{
    fprintf(stderr, "Could not initialize tesseract.\n");
    exit(1);
}

if(!api->SetVariable("tessedit_enable_doc_dict", "0"))
{
    cout << "Unable to enable dictionary" << endl;
}

只需将“tessedit_enable_doc_dict”作为参数传递给SetVariable函数,它就是相应的布尔值.

我在tesseractclass.h https://tesseract-ocr.github.io/a00736_source.html头文件(第839行)中找到它,我想找到正确参数的最佳方法是查看它定义的值(与您的版本对应的头文件.我的是3.04).
我试过很少,我之前在网上找到但没有工作.这是我的工作配置.

-------------------------------------------------------------------

 

我试图配置tesseract只识别完整的字典单词。这是:没有特殊字符,没有后缀或前缀等。


由于tessdata文件夹从这个项目不包含任何配置,我以为我会设置配置上init 。 

现在我试图通过修改claseAuxiliar.mm设置配置,但我不能说我注意到任何区别,这可能是因为配置错误或我设置他们错了。下面是我的配置,以及我目前如何设置它们:

 

  //初始化tesseract引擎。 
tesseract = new tesseract :: TessBaseAPI();
tesseract-> Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding],eng);
if(!tesseract-> SetVariable(segment_penalty_dict_nonword,10))
printf(Setting variable failed !!! \\\
);
if(!tesseract-> SetVariable(segment_penalty_garbage,10))
printf(Setting variable failed !!! \\\
);
if(!tesseract-> SetVariable(stopper_nondict_certainty_base, - 100))
printf(Setting variable failed !!! \\\
);
if(!tesseract-> SetVariable(language_model_penalty_non_dict_word,1))
printf(Setting variable failed !!! \\\
);
if(!tesseract-> SetVariable(language_model_penalty_non_freq_dict_word,1))
printf(Setting variable failed !!! \\\
);
if(!tesseract-> SetVariable(GARBAGE_STRING,5))
printf(Setting variable failed !!! \\\
);
if(!tesseract-> SetVariable(NON_WERD,5))
printf(Setting variable failed !!! \\\
);

 

解决方案

您可能想要抑制系统字典,加载替代自定义字典。



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

 ------------------------

 

 

 
posted @ 2020-05-26 16:08  汉学  阅读(336)  评论(0)    收藏  举报