Tesseract: How Computers Learned to Read
Today every phone can read text from its camera: point it at a receipt, a sign or a serial number and the text is there to copy. Few people know that part of how this works comes from Finland.
To a computer, a photo of a serial number is just an array of numbers, with no letters or even boundaries between them. Turning it into text is the job of OCR (optical character recognition), and Tesseract is one of the best-known open-source OCR engines. Its history follows computer vision from geometry and statistics to deep learning, and one of its methods was developed at the University of Oulu.
Four decades in brief
1985–1994 · Hewlett-Packard. Tesseract is developed in HP's research labs, with Ray Smith as one of its key authors.
2005–2006 · Open source. HP releases the code; from 2006 Google continues the project.
2018 · Tesseract 4. A neural line recogniser based on LSTM becomes the main engine.
2021 · Tesseract 5. Adds the Adaptive Otsu and Sauvola binarisation methods.
Today it is open source under the Apache 2.0 licence [1], [2].
or scanner→Binarisation→Page and
line analysis→Neural
network→UTF-8 text
The Finnish connection: from Oulu to Tesseract 5
In 1997 University of Oulu researchers Jaakko Sauvola, Tapio Seppänen, Sami Haapakoski and Matti Pietikäinen presented Adaptive Document Binarization at ICDAR [3]. In 2000 Sauvola and Pietikäinen published an extended version in Pattern Recognition [4]. One of its methods, now known as Sauvola thresholding, became part of Tesseract 5 more than twenty years later [5].
The problem they solved appears whenever you photograph a label in poor light: background in shadow can be darker than letters in the light, so a single brightness threshold loses part of the text.
Global threshold: Otsu's method
Nobuyuki Otsu (1979) picks the threshold t that maximises the between-class variance of dark and light pixels [6]:
ω are the shares of pixels in the two groups, μ their mean brightness. It works when text and background separate cleanly across the whole image.
Local threshold: Sauvola's method
Sauvola computes a threshold for every pixel from its neighbourhood: the local mean m reflects the lighting, the standard deviation s the contrast.
R is a normalising constant (usually 128) and k a sensitivity factor. With integral images (tables of cumulative sums) the statistics of any window take four lookups, so this is fast; the demo below uses that trick.
Japan, 1979 vs Finland, 2000
Change the lighting and the parameters. Both algorithms really run on this synthetic label.
It isn't universal either: too small a window breaks wide strokes, too large a window misses sharp lighting changes, and too high a k erases faint text.
From geometry to neural networks
The classic engine found connected components (groups of touching dark pixels), but a component is not always a letter: the dot of an i is separate, and neighbouring letters can touch. It split joined characters at concave points of their outlines and used A* search to combine the fragments [1].
Since Tesseract 4 the core is a network that reads a whole line. Convolutional layers extract visual features; bidirectional LSTM layers [7] carry context along the line, which helps tell O from 0 or rn from m. Architectures are described in Tesseract's own small language, VGSL [8].
CTC: training without marking every letter
Connectionist Temporal Classification (CTC, Graves et al., 2006 [9]) lets a network learn from “line image + correct text” pairs without the position of each character. The network outputs one symbol per step, including a blank. Repeats are merged first, then blanks removed, so a double letter needs a blank between its halves.
How BOOK turns into BOK
Shows the CTC collapsing rule only, not training or probabilistic decoding.
Where it runs and what it's good at
Tesseract is C++ on top of the Leptonica image library and needs only a CPU: no GPU, no internet. It runs on desktops and servers, Raspberry Pi-class boards, Android and iOS via wrappers, and in the browser via Tesseract.js [10], but not on typical microcontrollers. Models come as tessdata, tessdata_fast and tessdata_best, trading accuracy for speed and size [11].
| Task | Fit |
|---|---|
| Printed text, books, documents | The main use case. |
| Serial numbers, factory labels | Works with good images and the right segmentation mode. |
| Chip markings | Depends on sharpness, glare and character size. |
| Handwriting | The standard models are generally not suited to cursive. |
| Tables, formulas | Characters can be extracted; the structure needs other tools. |
| Barcodes, faces, objects | Need other, specialised algorithms. |
In industry, the camera matters more than you'd think
Optics, focus, lighting and glare can ruin an image before the network sees it. A production system should limit the search area, correct the geometry, pick the segmentation mode and validate the result against the expected format.
and lighting→OpenCV
geometry, ROI→Tesseract
OCR→Format, checksum,
database
For an image of a single line, for example:
tesseract label.png stdout --psm 7 -l eng -c thresholding_method=2
In Tesseract 5, thresholding_method=2 selects Sauvola. A starting point, not a guaranteed best setting for every label.
Why 99% may not be enough
OCR is usually measured by character error rate, but for serial numbers what counts is whole strings. If each character is right with probability p and errors are independent, a string of length n is fully correct with probability pⁿ.
The cost of one error
A theoretical model of independent errors, not a measured accuracy of Tesseract.
At 99% per character and 20 characters, only about 82% of strings are read perfectly. That's why industrial use needs checksums, repeated reads and database checks.
And in the age of LLMs?
Multimodal models can read text too, but a dedicated OCR engine is still the right tool when you need character coordinates, predictable output and offline work on a CPU. The two combine well: OCR extracts the text, a language model interprets it. And Sauvola's algorithm is a good reminder that new methods don't always replace the classic ones: research done in Oulu in the 1990s now runs inside a neural OCR engine.
Sources
- Ray Smith. An Overview of the Tesseract OCR Engine (2007).
- Tesseract OCR: source code and licence.
- Sauvola et al. Adaptive Document Binarization (1997).
- Sauvola, Pietikäinen. Adaptive Document Image Binarization (2000).
- Tesseract documentation: Improving the quality of the output.
- Otsu. A Threshold Selection Method from Gray-Level Histograms (1979).
- Hochreiter, Schmidhuber. Long Short-Term Memory (1997).
- Tesseract: VGSL Specification.
- Graves et al. Connectionist Temporal Classification (2006).
- Tesseract.js.
- Tesseract: Data Files.
The demos run locally in your browser with no external libraries and send no data. They don't run the OCR engine itself and are not a benchmark of its accuracy.
