gpt4 book ai didi

c++ - tesseract 虚假信心决定

转载 作者:搜寻专家 更新时间:2023-10-31 01:39:32 26 4
gpt4 key购买 nike

我正在使用 tesseract 进行序列号识别。在 tesseract 中,可以识别不同级别的文本,例如识别单个单词、行、段落、字符。也有可能获得每个级别的置信度。所以我查看了序列号中每个字符的置信度,发现 tesseract 通常返回的不是置信度最高的字符作为最佳选择。有人也遇到过这种情况吗?我在识别时做错了什么吗?

这种情况的例子,正确的序列号应该是:OC2VRHT5 看看最后一个字符。虽然“5”的置信度较高,但tesseract还是将“S”作为最佳选择。

**Tesseract output:**
symbol O, conf: 88.679855 - O conf: 88.679855
- 0 conf: 88.592140
- G conf: 77.554398
- C conf: 76.861900
- U conf: 75.981255
- Q conf: 75.135574
---------------------------------------------
symbol C, conf: 86.341553 - C conf: 86.341553
- Q conf: 71.356201
---------------------------------------------
symbol Z, conf: 77.400093 - 2 conf: 88.078430
- Z conf: 77.400093
---------------------------------------------
symbol V, conf: 93.404572 - V conf: 93.404572
---------------------------------------------
symbol R, conf: 93.212280 - R conf: 93.212280
---------------------------------------------
symbol H, conf: 84.634628 - H conf: 84.634628
- N conf: 75.782585
---------------------------------------------
symbol T, conf: 92.986008 - T conf: 92.986008
---------------------------------------------
symbol S, conf: 79.127983 - 5 conf: 84.440292
- S conf: 79.127983
- B conf: 78.667168
- G conf: 78.661667
---------------------------------------------

我的实现:

//Initializing tesseract
tesseract::TessBaseAPI tess;
tess.Init(NULL, "eng", tesseract::OEM_TESSERACT_ONLY);
tess.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);

tess.SetImage((uchar*) cropImage.data, cropImage.cols, cropImage.rows, 1,
cropImage.cols);
tess.SetVariable("save_blob_choices", "T");
tess.Recognize(0);

char* out = tess.GetUTF8Text();
std::cout << out << std::endl; //=> OCZVRHTS

tesseract::ResultIterator* ri = tess.GetIterator();
tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;

if (ri != 0) {
do {
const char* symbol = ri->GetUTF8Text(level);
float conf = ri->Confidence(level);
if (symbol != 0) {
printf("symbol %s, conf: %f", symbol, conf);
bool indent = false;
tesseract::ChoiceIterator ci(*ri);
do {
if (indent)
printf("\t \t \t");
const char* choice = ci.GetUTF8Text();
printf("\t- %s conf: %f\n", choice, ci.Confidence());
indent = true;
} while (ci.Next());
}
printf("---------------------------------------------\n");
delete[] symbol;
} while ((ri->Next(level)));
}

编辑

虽然我一开始以为jaka-konda的回答解决了我的问题,但似乎有时结果更好,但有时tesseract也没有取最高置信度的字符。进一步调查需要更大的数据库,但似乎 tesseract 字典没有完全禁用。

最佳答案

当您对每个符号进行迭代时,文本识别仍然基于整个收集和字典完成。在您的示例中,一个单词在中间包含数字的概率极低,这就是为什么它们被具有更高概率(字符)的选项替换的原因。为了解决这个问题,我建议降低字典影响值。

尝试将这些变量设置为 false:

load_system_dawg 
load_freq_dawg
load_punc_dawg
load_number_dawg
load_unambig_dawg
load_bigram_dawg
load_fixed_length_dawgs

Tesseract 常见问题解答:How to increase the trust in/strength of the dictionary?

代码:

GenericVector<STRING> pars_vec;
pars_vec.push_back("load_system_dawg");
pars_vec.push_back("load_freq_dawg");
pars_vec.push_back("load_punc_dawg");
pars_vec.push_back("load_number_dawg");
pars_vec.push_back("load_unambig_dawg");
pars_vec.push_back("load_bigram_dawg");
pars_vec.push_back("load_fixed_length_dawgs");

GenericVector<STRING> pars_values;
pars_values.push_back("0");
pars_values.push_back("0");
pars_values.push_back("0");
pars_values.push_back("0");
pars_values.push_back("0");
pars_values.push_back("0");

tesseract::TessBaseAPI tess; // = new tesseract::TessBaseAPI();
tess.Init(NULL, "eng", tesseract::OEM_TESSERACT_ONLY, NULL, 0, &pars_vec,
&pars_values, false);

正在使用参数初始化 tesseract Tesseract-OCR API

关于c++ - tesseract 虚假信心决定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31088854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com