image-to-text Β· vision β text (OCR) Β· WASM Β· ~340 MB
This is the base-sized TrOCR printed-text checkpoint β roughly 2.5Γ the
parameters of the small model, traded for materially better
accuracy on hard print: small type, low contrast, dense labels. A Vision Transformer
looks at a cropped line of text and a text decoder writes it out, one token
at a time β GRAND TOTAL: $42.99 β entirely on your device.
| Model | Xenova/trocr-base-printed |
|---|---|
| Task / pipeline | image-to-text |
| Architecture | ViT-style image encoder β RoBERTa-style text decoder (VisionEncoderDecoder, cross-attention), base size (~334M params) |
| Input | A single line of printed text (crop to the line you want) |
| Output | The transcribed characters, generated token by token |
| Quantization | q8 (8-bit) ONNX β separate encoder + decoder graphs |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~340 MB, cached after first load |
| License | MIT (microsoft/trocr-base-printed) |
| Vs the small model | Slower per line (~2.5 s vs ~0.7 s on WASM) but reads hard print the small checkpoint garbles |
| Web APIs | WebAssembly, Web Workers, Canvas, FileReader β all Baseline widely available |
Pick or drop an image, then drag a box around one line of text and hit Read. TrOCR is a single-line reader, so the crop is the point β it transcribes what's inside the box.
Drag on the image to select a line.
OCR here is autoregressive generation, not template matching. The encoder reads the cropped line into patch embeddings once; then the decoder emits the transcription one token at a time, each conditioned on the image and everything decoded so far β which is why TrOCR can fix its own spelling from context. The trace below shows every streamed chunk as it arrived, with the elapsed time. The first token is the slow one (it includes the image encode); the rest come faster. The base model's decoder is deeper than the small one's, so per-token time is higher β the price of the extra accuracy.
Text trapped in an image is invisible to everything that isn't a person looking at it β you can't search it, copy it, translate it, or total it. OCR turns those pixels back into characters, and doing it locally makes it free, private, and offline-capable. The base checkpoint is the one to reach for when accuracy matters more than download size: faint receipts, dense product labels, small print on packaging.
Crop a line β a sign, a serial label, a receipt total β and read it, token by token.
Digitise a whole receipt line by line, then capture + validate a serial number.
Live webcam OCR β point your camera at text and read it on the fly.
OCR β translation: read foreign text, then translate it locally.
The base call is two lines with Transformers.js:
import { pipeline } from "@huggingface/transformers";
const reader = await pipeline(
"image-to-text",
"Xenova/trocr-base-printed",
); // downloads + caches ~340 MB once
const out = await reader(lineCropURL, { max_new_tokens: 48 });
// β [{ generated_text: "GRAND TOTAL: $42.99" }]
The important bit is the input: TrOCR expects one line of text, so this page
crops the region you box before handing it over. For "See inside", it passes a
TextStreamer into the same call β the streamer fires as each word chunk is
finalised (it flushes at whitespace boundaries), so the page renders the transcription as it
forms and records each chunk's arrival time, all off the
main thread in a Web Worker. Note: this SROIE-tuned checkpoint tends to normalise to
UPPERCASE β that's the model, not a bug.