recallA retrieval
field guide

OCR for Scanned Documents

Build this skill

Describe how OCR works, measure its errors with character error rate, and choose fixes for poor scans.

When a document is only a picture

Many important documents in Indian colleges and offices exist only as scans: signed circulars, stamped notices, old regulations, forms filled in by hand. To a computer, a scanned page is a grid of coloured dots. It contains no letters at all. Before it can be searched, a program has to look at the picture and work out which letters are on it. That process is called OCR, short for optical character recognition.

OCR is old technology, and for clean, printed pages it is very accurate. For real-world scans, with crooked pages, faint photocopies, stamps over text, tables and handwriting, it makes mistakes. Those mistakes matter more than they seem, because a search engine cannot find a word that OCR misread.

How OCR works

Modern OCR works in a few stages.

Clean theimagestraighten,sharpenFind textregionsblocks andlinesRecognisepixels →charactersRebuildlayoutorder,paragraphsText +confidencewith pagepositions

OCR cleans the image, finds where text is, recognises the characters and rebuilds the reading order.

Image clean-up straightens tilted pages, increases contrast and removes noise. Text detection finds where on the page the text is, line by line. Recognition turns each line of pixels into characters, usually with a neural network trained on millions of examples. Layout reconstruction puts the lines back in reading order and groups them into paragraphs, columns and tables. Many OCR engines also return a confidence score for each word, which is very useful for spotting doubtful text later.

Two open-source engines are widely used. Tesseract, originally developed at HP and later maintained with Google's support, is a long-standing, lightweight engine that supports over 100 languages, including Hindi, Bengali, Tamil and Telugu. PaddleOCR, from Baidu's PaddlePaddle team, uses newer deep-learning models and often does better on difficult layouts, rotated text and mixed scripts. Layout-aware parsers such as Docling can call an OCR engine automatically when they meet a scanned page.

The mistakes OCR makes

OCR errors follow patterns. Characters that look alike get swapped: the letter l, the digit 1 and the capital I; the letter O and the digit 0; "rn" read as "m". Words get split or joined. Stamps and signatures that overlap text produce garbage characters. Faint or low-resolution scans lose letters entirely. Tables lose their structure, so numbers end up in the wrong rows.

Read the same scanned circular through three set-ups below and look at what each error would do to a search.

Why OCR errors hurt retrieval

A single wrong character can make a word unfindable by keyword search: "rnedical" will never match "medical". Embedding models are a little more forgiving of spelling noise, but heavy errors still push a passage's embedding away from its true meaning. Worse, OCR errors in numbers are dangerous for RAG: if "10 days" is read as "16 days", the system will retrieve the passage correctly and the language model will confidently repeat the wrong number.

A standard way to measure OCR quality is the character error rate (CER): the number of character changes needed to turn the OCR output into the correct text, divided by the length of the correct text. A CER of 2 percent sounds small, but it means roughly one wrong character every 50, which is about one error per sentence. The program below computes CER for a short line.

python · runs in your browser

Expected output:

text
character errors: 6
character error rate: 9.7%

edit_distance fills in a table one row at a time. Each entry is the cheapest way to turn the first few characters of one string into the first few of the other, choosing between deleting a character, inserting one, or swapping one (which is free when the two characters already match). The last entry is the answer. Six character edits in a 62-character sentence give an error rate of nearly 10 percent, and each error sits inside a word a student might search for.

Getting better OCR results

Most OCR quality comes from a few habits.

  • Scan well. 300 dots per inch is a common recommendation for text; photos taken at an angle on a phone are much worse.
  • Pick the right language packs. An engine told to expect only English will mangle Hindi or Telugu text.
  • Use the born-digital version when one exists. If the original Word or PDF file is available, never OCR a scan of it.
  • Keep confidence scores and page positions. Low-confidence words can be flagged for review, and page positions let an answer link back to the exact spot on the scan.
  • Check numbers and names. These are the facts people ask about and the characters OCR most often confuses.

Decide which fix suits each problem.

Follow your curiosity.

↑ ↓ to explore · Enter to open · Escape to close