Measuring OCR accuracy with a sample

Updated

"The OCR is about 99% accurate" is a sentence that usually means nobody measured it. A small, repeatable sample is enough to get a real number, and the number is useful: it tells you whether a batch can be searched with confidence, whether a setting change helped and which document types need extra attention.

The metric

The standard measure is the character error rate, or CER. Take the correct text for a passage (the ground truth), compare it with what the OCR produced and count the minimum number of single-character edits that turn one into the other: substitutions, deletions and insertions. Divide by the number of characters in the ground truth. A CER of 1% means that roughly one character in a hundred is wrong. Word error rate is stricter, since one wrong letter spoils a whole word, and is worth tracking if search is your main use case.

Drawing the sample

  1. Split the batch into strata that behave differently: clean prints, forms and tables, old typewritten pages, handwriting-heavy pages.
  2. From each stratum pick pages at random, not the first few and not the ones that look interesting. A spreadsheet random number or a shuffled file list is fine.
  3. From each page take a block of 5 to 10 lines. Whole pages are slow to correct and add little precision.
  4. Aim for at least 30 pages per stratum, or 100 for a batch of several thousand pages. Small samples give wide error bars, so report a range rather than a single figure.

Building the ground truth

Type the selected lines yourself, or correct the OCR output by hand while looking at the image. The second approach is faster but biased: it is easy to overlook an error that looks plausible. Having a second person review the corrected text catches most of those. Keep the ground truth in plain text files named after the page, one block per file.

Counting edits

Any diff tool that works at character level will do, and a short script computing Levenshtein distance is easy to write. Normalise before comparing: decide whether line breaks, hyphenation at line ends and repeated spaces count as errors, and apply the same rule everywhere. A single quote style mismatch can inflate the count by hundreds of characters if you forget this step.

Reading the result

Look at which characters fail most often. Confusions between 0 and O, 1 and l, or missed diacritics are fixable with a language or dictionary setting. Errors concentrated in tables suggest turning off automatic layout analysis for those pages.

Repeat the measurement whenever you change the scanner, resolution, engine version or language setting, and file the numbers with the batch notes. After a few batches you will know what a normal result looks like and will notice quickly when one is not.

Three-step diagram: sample pages, type the ground truth, compare with OCR output to get the character error rate
From sample to character error rate in three steps.
expertscan.com — notes on scanning, OCR and document archives© 2026