title: Calculate OCR accuracy
body: <p>I need to calculate OCR character accuracy</p>
  <p><strong>Sample ground value:</strong></p>
  <p><code>Non sinking ship is friendship</code></p>
  <p><strong>Sample ocr value input</strong>:</p>
  <p><code>non singing ship is finedship</code></p>
  <p>Areas of concern are:</p>
  <ol>
  <li>missed characters</li>
  <li>extra characters</li>
  <li>misplaced characters</li>
  </ol>
  <p>Character accuracy is defined by the number of actual characters with their places divided by the total of actual characters.</p>
  <p>I need a python script to find this accuracy. My initial implementation is as follows:</p>
  <pre><code>ground_value = &quot;Non sinking ship is friendship&quot;
  ocr_value = &quot;non singing ship is finedship&quot;
  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
  </code></pre>
  <p>I couldn't get what I was hoping for. Any help would be appreciated.</p>