【问题标题】:How to calculate confidence score of OCR system?如何计算 OCR 系统的置信度分数?
【发布时间】:2020-07-17 11:55:27
【问题描述】:

我正在从事一个 OCR 项目,我想知道如何计算我的 OCR 系统的置信度分数。

我有数字万用表图像。图像中的设备屏幕上有一些测量结果。我想承认这些价值观。但是,根据我的研究,我不确定哪种 OCR 置信度计算技术适合我的系统。

据我了解,OCR 置信度分数可以在字符、单词和句子方面进行计算。实际上,最后两种方法建立在字符置信度分数之上。就我而言,按字符计算可能是错误的或不够的。

例如,我有“40.245 V”文本。我得到了两个不同的识别结果,如“40.247 V”和“70.245 V”。如果我没记错的话,两个结果都将具有相同或接近的置信度分数。然而,“40.247 V”的预测是可以接受的,而“70.245 V”在我的情况下是不可接受的。

你知道如何计算这个案例的置信度分数吗?

【问题讨论】:

    标签: python ocr tesseract python-tesseract text-recognition


    【解决方案1】:

    在计算置信度时,您会生成置信度的加权平均值,以便为第一个字符赋予更大的权重,而对最后一个字符赋予更少的权重。

    #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)时

    如果您认为某些职位比其他职位更有价值,您可以指定不同的权重。

    【讨论】:

      猜你喜欢
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 2021-02-20
      • 2020-12-11
      • 2018-05-28
      相关资源
      最近更新 更多