在 tesseract C++ 中禁用字典辅助 OCR API
Disable dictionary-assisted OCR in tesseract C++ API
我有一个应用程序,其中使用 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.
您可以简单地将惩罚设置为零:
tess.SetVariable("segment_penalty_garbage", "0");
tess.SetVariable("segment_penalty_dict_nonword", "0");
tess.SetVariable("segment_penalty_dict_frequent_word", "0");
tess.SetVariable("segment_penalty_dict_case_ok", "0");
tess.SetVariable("segment_penalty_dict_case_bad", "0");
虽然字典仍然保持活动状态,但这种方法基本上告诉算法字典命中(也包括错误的标点符号等)并不比非字典命中好。
对于 tesseract 3.02,您只能在 initialization of API. See tesseract-ocr API example in C++ of changing init parameters 期间关闭字典。
您可以按照以下方式进行
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 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.
您可以简单地将惩罚设置为零:
tess.SetVariable("segment_penalty_garbage", "0");
tess.SetVariable("segment_penalty_dict_nonword", "0");
tess.SetVariable("segment_penalty_dict_frequent_word", "0");
tess.SetVariable("segment_penalty_dict_case_ok", "0");
tess.SetVariable("segment_penalty_dict_case_bad", "0");
虽然字典仍然保持活动状态,但这种方法基本上告诉算法字典命中(也包括错误的标点符号等)并不比非字典命中好。
对于 tesseract 3.02,您只能在 initialization of API. See tesseract-ocr API example in C++ of changing init parameters 期间关闭字典。
您可以按照以下方式进行
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)。
我尝试了一些以前在互联网上找到的方法,但没有用。这是我的工作配置。