我正在做一个OCR项目,我想知道如何计算我的OCR系统的置信度分数。
我有数字万用表图像。在设备的屏幕上有一些图像的测量结果。我想要认识到这些价值观。然而,根据我的研究,我不确定哪种OCR置信度计算技术适合我的系统。
据我所知,OCR置信度分数可以在字符、单词和句子方面进行计算。实际上,后两种方法建立在字符置信度分数的基础上。在我的例子中,按字符计算可能是错误的或不充分的。
例如,我有"40.245 V“文本。我得到了两种不同的识别结果,比如"40.247 V“和"70.245 V”。如果我没有错,两个结果都会有相同或接近的置信度分数。然而,"40.247 V“的预测是可以接受的,而"70.245 V”在我的情况下是不可接受的。
有没有办法计算这种情况下的置信度得分?
发布于 2020-07-23 12:13:55
在计算置信度时,您会生成置信度的加权平均值,以便为前几个字符赋予更多权重,而为最后一个字符赋予较少的权重。
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
using namespace std;
double getWeightedConfidence(vector<pair<char /* character */, double /*confidence of that character */>> word) {
if (word.empty()) {
return 1.0;
}
double confidence = 0;
if (isdigit(word[0].first)) {
// okay it is a number
double weight = 1;
double sumOfWeights = 0;
for (const auto &c : word) {
confidence += c.second * weight;
sumOfWeights += weight;
weight /= 10; // you can decay it by whatever number you want based on how much do you think next digit is less valueble then previous
}
confidence /= sumOfWeights;
} else {
// not a number - just calculate a normal average
for (const auto &c : word) {
confidence += c.second;
}
confidence /= word.size();
}
return confidence;
}
int main() {
vector<pair<char, double>> number_with_first_digit_wrong;
number_with_first_digit_wrong.emplace_back('7', 0.1);
number_with_first_digit_wrong.emplace_back('4', 0.9);
number_with_first_digit_wrong.emplace_back('6', 0.9);
number_with_first_digit_wrong.emplace_back('2', 0.9);
number_with_first_digit_wrong.emplace_back('.', 0.9);
number_with_first_digit_wrong.emplace_back('9', 0.9);
vector<pair<char, double>> number_with_last_digit_wrong;
number_with_last_digit_wrong.emplace_back('7', 0.9);
number_with_last_digit_wrong.emplace_back('4', 0.9);
number_with_last_digit_wrong.emplace_back('6', 0.9);
number_with_last_digit_wrong.emplace_back('2', 0.9);
number_with_last_digit_wrong.emplace_back('.', 0.9);
number_with_last_digit_wrong.emplace_back('9', 0.1);
cout << getWeightedConfidence(number_with_first_digit_wrong) << " " << getWeightedConfidence(number_with_last_digit_wrong) << endl;
return 0;
}
像这样简单的东西会给出结果:
0.179999 -当0.1是第一个数字的置信度(其他是0.9) 0.899993 -当0.1是最后一个数字的置信度(其他是0.9)
如果您认为某些位置比其他位置更有价值,则可以指定不同的权重。
https://stackoverflow.com/questions/62953451
复制