How to measure OCR accuracy: character and word error rate

Updated · Tested with Python 3.13, jiwer 4.0.0, Tesseract 5.5.0

In short

Compare the OCR text with the true text and count the characters that had to be substituted, deleted or inserted. Divided by the length of the true text, that is the character error rate. The word error rate counts whole words and is stricter. In Python, the jiwer package computes both in one call each.

"The OCR looks fine" is not a measurement. To compare two engines, two settings or two scanners, you need a number, and the two standard ones are the character error rate and the word error rate.

The two numbers

Take the text OCR produced and the text that is really on the page. Count the smallest number of single edits that turn one into the other: characters substituted, deleted and inserted.

Character error rate (CER) = (substitutions + deletions + insertions) / characters in the true text.

Word error rate (WER) is the same count made on whole words: one wrong letter makes the whole word wrong.

True textOCR textEditsCERWER
Share capital 1,250.50Share capital 1,250.5000%0%
Share capital 1,250.50Share capital 1250502 deletions9.1%33.3%

One line, two characters lost, and the amount is wrong by a factor of a hundred. CER says 9%; WER says a third of the words are wrong. WER is the stricter number and usually the more honest one for data, because a number with one wrong digit is simply wrong.

Measure it in Python

The jiwer package computes both.

Shell
pip install jiwer pytesseract pillow

You need the true text of at least a few pages, typed or checked by a person. This is the text of our sample page, company-scan-300dpi.png:

Python
import jiwer
import pytesseract
from PIL import Image

truth = """COMPANY EXTRACT
Company name Harbor Lane Logistics Ltd
Company number 51-482913-6
Status Active
Registered 14 March 2019
Registered office 22 Quay Street, Haifa
Share capital 1,250.50
Directors
Dana Levi, Chairperson
Omer Cohen, Director
Charges
2 active, 1 released
This extract lists the details held in the register on 3 November 2026. It is a sample document with fictional
data."""

def normalise(text):
    return " ".join(text.split())

def score(path):
    result = normalise(pytesseract.image_to_string(Image.open(path)))
    expected = normalise(truth)
    return jiwer.cer(expected, result), jiwer.wer(expected, result)

for name in ["company-scan-300dpi.png", "company-scan-100dpi.png", "company-scan-60dpi.png"]:
    cer, wer = score(name)
    print(f"{name}  CER {cer:.1%}  WER {wer:.1%}")
Output
company-scan-300dpi.png  CER 0.0%  WER 0.0%
company-scan-100dpi.png  CER 0.5%  WER 5.1%
company-scan-60dpi.png  CER 49.9%  WER 72.9%

Look at the middle line. Half a percent of the characters sounds excellent, and it is still one word in twenty.

Decide what counts as a difference

normalise above turns every run of spaces and line breaks into one space, so the score ignores layout and counts only text. Whatever you choose, apply it to both sides:

  • Whitespace and line breaks. Usually ignore them, as here.
  • Upper and lower case. Keep it for names and codes; ignore it for search.
  • Punctuation. Keep it when you extract amounts and dates; a lost decimal point matters.
  • Invisible marks. OCR of right-to-left text adds direction marks. Strip them first.

Report what you normalised together with the number. A CER without its rules cannot be compared with anyone else's.

Rates above 100%

The error rate is divided by the length of the true text, so an engine that invents a lot of extra text scores above 100%. When we over-filtered a noisy photo, Tesseract returned pages of invented characters and the CER passed 1,000%. That is not a bug in the formula. It tells you the output is worse than an empty page, which would score exactly 100%.

How many pages you need

  • Use pages like the ones you will really process: the same scanner, the same forms, the bad ones included.
  • Start with twenty to fifty pages, and add more when two setups score within a percent of each other.
  • Score each page separately and look at the worst ones, not just the average. One unreadable page in fifty is hidden by an average and found by your customer.

Measure the fields, not just the page

If you extract ten values from each document, the number that matters is how many of those values are right. A page can be 99% correct and still have the invoice total wrong. For each field, compare the extracted value with the true one, exactly, and report the share that match. It is cruder than CER and closer to what a wrong result costs.

What a good number is

For printed text scanned at 300 DPI, a current engine should be at or near 0% CER, as in the first row above. A few percent means something is off: resolution, rotation, language, or noise. How to improve OCR accuracy goes through each with before-and-after figures.

The same method works on any engine: replace the pytesseract call in the script with a call to the engine or service you are testing.

Questions

What is a good OCR accuracy?

For printed text scanned at 300 DPI, a current engine should be at or near a 0 percent character error rate. A few percent means something is off: resolution, rotation, language or noise.

What is the difference between CER and WER?

CER counts wrong characters and WER counts wrong words. One wrong letter makes a whole word wrong, so WER is higher and stricter. On one of our test files CER was 0.5 percent and WER was 5.1 percent.

Can an error rate be more than 100 percent?

Yes. The count of errors is divided by the length of the true text, so an engine that invents a lot of extra text scores above 100 percent, which is worse than returning nothing.

How many pages do I need to test OCR?

Start with twenty to fifty pages that look like the ones you will really process, including the bad ones, and look at the worst pages as well as the average.

Try it on your own documents

A free plan every month, no credit card. See the PDF to text API.

Start free
  • How to improve OCR accuracy

    One page read by Tesseract in six conditions, with the error rate for each: what resolution, rotation and noise do, and the fixes that work, with measurements.

  • How to OCR a scanned PDF in Python

    Read scanned PDFs in Python with Tesseract: turn pages into images with PyMuPDF, run pytesseract, OCR only the pages that need it, and get word positions.

  • How to choose a PDF extraction API: nine things to test

    Nine tests to run on any PDF or OCR extraction API with your own documents: text order, scans, languages, repeatability, errors, limits, price and privacy.