← All models

object-detection (text) Β· vision Β· WASM Β· ~83 MB

CRAFT β€” where is the text, character by character?

A text detector doesn't read words β€” it finds where they are. CRAFT (Character-Region Awareness For Text detection) does it with two heatmaps: a region map (per-pixel "is this a character?") and an affinity map (per-pixel "do two characters belong to the same word?"). The affinity map bridges the gaps between letters, so characters group into oriented word boxes β€” even curved or slanted lines. It runs entirely on your device via ONNX Runtime Web; the image and the boxes never leave the tab. This is a different approach from the DBNet detector (one binarization map) β€” CRAFT reasons about characters and the links between them. Detection locates text; reading it is a separate step (see the multi-model demo).

At a glance

Modelinference4j/craft-mlt-25k β€” CLOVA AI CRAFT (VGG16-BN backbone), the EasyOCR detector
Taskobject-detection (text-region detection) β€” run via raw ONNX Runtime Web (see note below)
Runtimeonnxruntime-web 1.21 (transformers.js has no CRAFT class)
Input[1, 3, H, W] NCHW β€” the image resized so H,W are multiples of 32, ImageNet-normalised
Output[1, H/2, W/2, 2] β€” channel 0 = region (character) heat, channel 1 = affinity (character-link) heat; decoded (threshold β†’ OR β†’ connected components β†’ min-area box) into word polygons
Quantizationfp32 ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~83 MB, cached after first load
LicenseMIT (ONNX export) Β· CRAFT / CLOVA AI
Web APIsWebAssembly, Web Workers, OffscreenCanvas, Canvas β€” all Baseline widely available

Run it

Pick a sample (or drop your own image), then detect. The model returns oriented boxes around every word β€” it does not read the words.

CafΓ© storefront sign with several lines of text Grocery receipt with itemised lines Book page paragraph Poster with rotated, angled text Street scene with mixed signage
Drop / choose your own image

Everything runs on your device β€” the image, the heatmaps, and the boxes never leave the tab. The samples are generated for this demo (no real people or brands).

See inside

CRAFT's real output isn't boxes β€” it's two heatmaps. The region map lights up on each character; the affinity map lights up between characters that belong to the same word. Threshold both, OR them together, group the connected blobs, and fit a minimum-area box to each β€” that's the whole CRAFT decode, made visible. The affinity map is what lets one word become one box instead of a box per letter.

Detect an image to see its region + affinity maps.

Why it matters

Detection is the first stage of every OCR and document pipeline β€” and doing it on-device means a sensitive document (a receipt, an ID, a form) never has to be uploaded to find its text. CRAFT's character-affinity approach is especially good at word-level boxes and curved or angled lines. Once you know where text is, you can act on regions without reading a word:

This detector locates words; it does not recognise characters, languages, or reading order β€” pair it with an OCR model for that.

Use cases

Basics

One image in, oriented word boxes out β€” see CRAFT find every word and count them.

Practical

On-device redaction β€” detect every word in a document and black it out before sharing.

Wild

Rotated, angled, dense text β€” watch the affinity map link letters into tilted word boxes.

Multi-model

Detect β†’ read: locate each word, crop it upright, then run TrOCR to actually read it.

How the API works

transformers.js has no CRAFT class, so we run the ONNX graph directly with ONNX Runtime Web. The model gives two heatmaps; the CRAFT decode turns them into word boxes:

import * as ort from "onnxruntime-web";

const session = await ort.InferenceSession.create(craftBytes, { executionProviders: ["wasm"] });

// image β†’ [1,3,H,W] NCHW (H,W multiples of 32), ImageNet-normalised
const input = new ort.Tensor("float32", normalize(image), [1, 3, H, W]);
const { score_map } = await session.run({ input });   // [1, H/2, W/2, 2]

// CRAFT decode: region>textThreshold OR affinity>linkThreshold β†’ connected components β†’ min-area box
const words = decode(score_map.data, W / 2, H / 2, { textThreshold: 0.7, linkThreshold: 0.4 });

Inference and the whole decode run in a Web Worker so the UI never blocks, and the 83 MB model is fetched through Cache Storage, so a returning visit auto-initialises with no re-download.

References