Table of Contents▼
• ... • • Comments • •

In-Browser OCR in 2026: Tesseract.js (WASM) vs. Florence-2 Vision AI (Live Demo)

Compare classic Tesseract.js WebAssembly OCR (~4 MB) side-by-side with Microsoft's Florence-2 Vision-Language Model running 100% locally in your browser via WebGPU.

Guy Mograbi
Guy Mograbi
Full Stack & Cloud Engineer

If you want to extract text from a screenshot, receipt, or whiteboard photo in a web app, you usually face two choices: send your user’s private image to a cloud Vision API, or run everything locally inside their browser tab.

After building in-browser neural TTS, client-side background removal, and Stockfish 19 chess in WebAssembly, I built a side-by-side In-Browser OCR Arena so you can pit Tesseract.js (WASM) directly against Microsoft’s Florence-2 Vision AI (onnx-community/Florence-2-base-ft) on the exact same image.


Wait: What Are These Two Models?

Both run 100% locally in your browser (check your Network tab—zero image bytes ever leave your device), and both use AI, just from completely different eras:

  1. Tesseract.js (WASM · ~4 MB): Originally built at HP in the 1980s and later upgraded by Google with LSTM neural networks, compiled to WebAssembly. It’s tiny, fast, and gives you exact word-level pixel coordinates—but assumes flat, black-ink-on-white-paper pages.
  2. Florence-2 (Florence-2-base-ft) (WebGPU · ~230 MB): Microsoft’s multimodal Vision-Language Foundation Model running via @huggingface/transformers. Because it understands visual context, it can read faint text, tilted receipts, and handwritten whiteboards where traditional OCR falls apart.
DimensionTesseract.js (WASM)Florence-2 (<OCR> via WebGPU)
Download Size~4 MB (WASM + .traineddata)~230 MB (cached in browser)
HardwareAny CPU (works everywhere)WebGPU (falls back to WASM)
Speed~0.2–1.5s~1.5–8s
Languages100+ (must pick upfront, e.g. eng+heb)English-centric, zero config
Word Bounding BoxesNative (blocks → paragraphs → lines → words)Optional via <OCR_WITH_REGION>
Best AtClean screenshots, code, receiptsStriped/noisy photos, handwriting, faint text

How the Zero-Backend Pipeline Works

flowchart LR
    Input["🖼️ Image / Dragged Region"] --> Prep["🎛️ B&W Preprocess + Auto-Invert"]
    Prep -->|"Clean pixels"| Tess["⚙️ Tesseract.js (WASM)<br/>PSM + Multi-Language"]
    Input -->|"Original RGB pixels"| Flor["🧠 Florence-2 (WebGPU)<br/>&lt;OCR&gt; / &lt;OCR_WITH_REGION&gt;"]
    Tess --> Compare["📊 Side-by-Side Output + Confidence"]
    Flor --> Compare

Four Engineering Details That Made It Actually Work

1. Passing <canvas> Directly (No Temporary blob: URLs)

When a user drops or pastes an image, URL.createObjectURL(blob) creates a temporary in-memory URL (blob:https://...). If you pass that string to a background Web Worker and revoke it too early, the worker’s fetch() crashes. Drawing onto an HTML5 <canvas> and passing the canvas element directly sends decoded pixels with zero URL lifetime bugs:

const { data } = await worker.recognize(canvas, { rectangle }, { text: true, blocks: true });

2. Visualizing Word Confidence & Layout Trees

Passing { text: true, blocks: true } tells Tesseract to return its full layout tree (Blocks → Paragraphs → Lines → Words) with per-word confidence (0–100) and bbox coordinates. We draw green boxes (>80%) and amber boxes (≤80%) over the image and show the exact word + confidence % on hover.

3. B&W Preprocessing & Center-Weighted Auto-Invert

Tesseract expects black ink on white paper—so dark-mode screenshots (like Demo 3: Dark Stack Trace) fail out of the box. Our B&W Preprocess toggle converts to grayscale, stretches contrast, and checks the center 50% luminance to auto-invert dark-mode images without accidentally inverting white-paper receipts photographed on a dark desk.

4. Exposing PSM (Page Segmentation Mode) & Region Selection

By default, Tesseract uses PSM 3 (Auto Page), which assumes a standard document. Switching to PSM 11 (Sparse) or PSM 6 (Single Block)—or dragging a box directly on the canvas to pass { rectangle }—stops Tesseract from trying to read background textures as text.


Try the 4 Demos Side-by-Side

Test Demo 1 (Receipt), Demo 2 (Striped Receipt), Demo 3 (Dark Stack Trace), and Demo 4 (Whiteboard) below—and click ▶ Run Florence-2 to see exactly where a tiny 4 MB WASM engine stops and a 230 MB Vision model takes over.

Ready — upload, drop, or paste (⌘V / Ctrl+V) any image
—
⚙️ Tesseract.js (WASM · ~4 MB)
🧠 Vision AI (Florence-2)

The Code

</>
Source Code Explorer
3files · live from repository