← All models

image-to-image (document dewarping) Β· vision Β· WASM Β· ~30 MB

UVDoc β€” flatten a warped document photo

Give this model a photo of a curled, skewed or perspective-distorted page β€” a book held open, a receipt on a table, a folded page shot at an angle β€” and it flattens it into a clean, rectangular, scanner-style document: straightened text lines, corrected geometry. UVDoc is the PaddleOCR document image unwarping model. It doesn't crop or rotate β€” it learns the page's 3D deformation and undoes it. Runs entirely on your device via ONNX Runtime Web; the document never leaves the tab.

At a glance

ModelPaddlePaddle/UVDoc_onnx β€” UVDoc, the PaddleOCR document image unwarping model
Taskimage-to-image (document dewarping / rectification) β€” run via raw ONNX Runtime Web (see note below)
Runtimeonnxruntime-web 1.21 (transformers.js has no UVDoc class / no document-unwarping task)
Inputimage [1, 3, H, W] float32 in 0–1 β€” the warped page, plain RGB (no normalisation), H/W rounded to a multiple of 32
Outputfetch_name_0 [1, 3, H, W] float32 in 0–1 β€” the flattened page (the unwarped image directly, not a grid)
Quantizationfp32 ONNX (single file) β€” runs on the plain WASM execution provider, no WebGPU needed
BackendWebAssembly (single-threaded on GitHub Pages) β€” a pass is roughly a second
Download~30 MB, cached after first load (auto-inits on return)
LicenseApache-2.0 (PaddleOCR / PaddlePaddle)
Web APIsWebAssembly, Web Workers, OffscreenCanvas, ImageBitmap β€” all Baseline widely available

Run it

Pick a page and add a known curl/skew so you can watch UVDoc flatten it β€” or drop your own photo of a genuinely warped document. Drag the divider to compare warped vs flattened.

β—€ warped inputflattened β–Ά
Drop / choose your own document photo (a curled or angled page works best)

Everything runs on your device β€” the document and every corrected pixel never leave the tab. Sample pages are rights-cleared (see each caption for the source).

See inside

UVDoc doesn't just crop or rotate β€” it predicts the page's continuous 3D deformation and resamples every pixel to undo it. That's why straight text lines that bowed in the photo come back straight, and a page shot at an angle becomes a front-on rectangle. Watch the edges of the page as you wipe: a plain crop would leave them curved; UVDoc straightens them.

Flatten a page to compare its geometry.

Why it matters

A photo of a page is not a scan β€” it's curled, skewed and lit unevenly, which wrecks OCR and looks unprofessional. On-device dewarping turns a phone photo into a clean document, privately and free:

UVDoc corrects geometric distortion; it doesn't invent text the photo never captured, and extreme folds or occlusions flatten only partially.

Use cases

Basics

Curl a page, then watch UVDoc flatten it β€” wipe between warped and flattened and see the text lines straighten.

Practical

Flatten a real photographed page and download the corrected scan-style image, ready to file or print.

Wild

Crank the curl to an extreme fold and find where geometric rectification starts to break down.

Multi-model

Dewarp β†’ read: flatten a page, then run the on-device text detector to see how many more lines OCR can find.

How the API works

transformers.js has no UVDoc class and no document-unwarping task, so we run the ONNX graph directly with ONNX Runtime Web. In goes the warped page, out comes the flattened one:

import * as ort from "onnxruntime-web";

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

// warped page β†’ [1,3,H,W] float32 in [0,1] (plain RGB, no normalisation)
const input = new ort.Tensor("float32", toNCHW(warped, W, H), [1, 3, H, W]);
const { fetch_name_0 } = await session.run({ image: input });

// fetch_name_0 is [1,3,H,W] in [0,1] β†’ the flattened page β†’ clamp to RGBA
const flat = tensorToImage(fetch_name_0.data, W, H);

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

References