Python 计算光学字符识别精度

Python 计算光学字符识别精度,python,python-3.x,computer-vision,ocr,Python,Python 3.x,Computer Vision,Ocr,我需要计算OCR字符的准确度 采样地面值: 不沉没的船就是友谊 样本ocr值输入: 不唱歌的船是好船 关注的领域包括: 遗漏字符 额外字符 错位字符 字符精度由实际字符数及其位置除以实际字符总数来定义 我需要一个python脚本来找到这种准确性。我的初步实施如下: ground_value = "Non sinking ship is friendship" ocr_value = "non singing ship is finedship" groun

我需要计算OCR字符的准确度

采样地面值:

不沉没的船就是友谊

样本ocr值输入

不唱歌的船是好船

关注的领域包括:

  • 遗漏字符
  • 额外字符
  • 错位字符
  • 字符精度由实际字符数及其位置除以实际字符总数来定义

    我需要一个python脚本来找到这种准确性。我的初步实施如下:

    ground_value = "Non sinking ship is friendship"
    ocr_value = "non singing ship is finedship"
    ground_value_characters = (re.sub('\s+', '',
                                          ground_value)).strip()  # remove all spaces from the gr value string
        ocr_value_characters = (re.sub('\s+', '',
                                       ocr_value)).strip()  # remove all the spaces from the ocr string 
    
     total_characters = float(len(
            ground_value_characters))  
    
    def find_matching_characters(ground, ocr):
      total = 0
      for char in ground:
        if char in ocr:
          total = total + 1
          ocr = ocr.replace(char, '', 1)
      return total
    
    found_characters = find_matching_characters(ground_value_characters,
                                                    ocr_value_characters)
    
    accuracy = found_characters/total_characters
    

    我无法得到我所希望的。任何帮助都将不胜感激。

    如果您还没有接受这个精确的定义(或者如果您是并且想要深入研究python Levenshtein的细节),那么我将这样解决这个问题:

    pip安装python Levenshtein

    从Levenshtein导入距离
    ground\u value=“不沉没的船就是友谊”
    ocr_value=“非歌唱船为精船”
    打印(距离(地面值、ocr值))
    
    这将以相对高性能的方式为您提供汉明距离、操作码和类似的功能


    如果这是一个家庭作业,或者你的目的是学习如何实现字符串算法,那么这些都没有用,但是如果你只是需要一个好的度量,这就是我要使用的。

    这与浮动精度无关。