What Is OCR and How Does It Work?

How a picture of text becomes editable text, step by step, and what decides whether the result is usable.

6 min read

The short definition

Optical character recognition converts pictures of text into characters a computer can search, copy and edit. The input is pixels, the output is a string. Everything in between is an attempt to answer one question repeatedly: which character does this cluster of dark pixels represent?

A photo of a page and a typed page look identical to you. To software they are completely different: one is a grid of colour values, the other is a sequence of codes. OCR bridges that gap.

The four stages of a typical pipeline

Pre-processing cleans the image. The page is straightened, converted to greyscale, contrast is stretched, and speckles from paper texture or JPEG compression are smoothed away. Most accuracy problems that look like recognition failures are actually pre-processing failures.

Layout analysis decides what is text and what is not. It finds columns, tables, headers, captions and images, then fixes a reading order. This is why a two-column PDF sometimes comes back with sentences interleaved: the reading order was guessed wrong.

Recognition runs the actual model over each text line. Modern systems predict whole sequences rather than isolated glyphs, so surrounding letters influence each decision.

Post-processing applies a language model and dictionary. It is what turns "reoeipt" into "receipt" and what occasionally turns a genuine product code into a dictionary word.

Why identical-looking images give different results

Resolution matters more than megapixels. What counts is pixels per character height: roughly 20 pixels tall per character is a workable minimum, 30 or more is comfortable. A 12-megapixel photo of a page taken from across the room can be worse than a modest 300 DPI scan.

Contrast and even lighting matter next. A shadow across half the page changes the threshold between ink and paper mid-line, and characters on the dark side get dropped.

Finally, the script and font. Standard Latin print is the best-served case. Cursive handwriting, decorative display faces, dot-matrix receipts and low-contrast thermal paper are all measurably harder.

When OCR is the wrong tool

If the PDF already contains a text layer, extract it directly rather than re-recognising an image of it. You get perfect fidelity instead of a good guess.

If you need certified accuracy, for example on legal or medical records, treat OCR output as a draft that a person checks. It speeds up transcription; it does not remove the need to verify.

Frequently asked questions

Tool for this

OCRGPTRead text out of images, scans and PDFs.

Open the OCRGPT page

More in OCR & Document Processing