Skip to main content

Flattener

Open-source SOTA document scanner.

Turn document photos and open books into flat, upright scans. Flattener detects pages, corrects orientation and curvature, and splits book spreads. Everything runs locally. Inference, training, data preparation and evaluation code are included.

See benchmark results and reproduction instructions.

Scan

uvx flattener-scan -i photo.jpg scan.jpg

Or install it with pip install flattener-scan and run flattener-scan -i photo.jpg scan.jpg. Flattener needs Python 3.12 or newer and is tested on Linux x86_64.

The models run on the CPU with ONNX Runtime, so the install stays small. To use an NVIDIA GPU, add PyTorch: uvx --with torch flattener-scan -i photo.jpg scan.jpg, or pip install "flattener-scan[torch]". With PyTorch installed, a CUDA GPU is used automatically; --device cpu or --backend onnx keeps the CPU.

The first scan downloads the Apache-2.0 models from Hugging Face, version 1.1.0. Later scans reuse the local Hugging Face cache and work offline. Set HF_HOME to choose a different cache directory.

Without an output name, the scan is saved as photo-scan.jpg in the current directory. Repeat -i for a batch and give an output directory: flattener-scan -i a.jpg -i b.jpg scans/. Book spreads produce separate page files, such as scan-p1.jpg and scan-p2.jpg. Existing files are kept unless you pass -y. Use --record to save a JSON record of each scan, or --json to print one. Use --region, --quad, --quarter or --output-size for manual control; run flattener-scan --help for all options.

From Python:

from flattener.scan.io import save_scan_files
from flattener.scan.pipeline import Scanner

scanner = Scanner.load()
result = scanner.scan("photo.jpg")
save_scan_files(result, "scan.jpg")

Use scanner.scan_pages("book.jpg") for automatic spread splitting.

To work from a clone of this repository, run uv sync and uv run flattener-scan. The development environment includes CPU PyTorch for training and evaluation.

Browser app

Scan single pages locally with WebGPU or CPU/WASM, edit the result and save a PNG. See the web app guide for setup, capabilities and static hosting.

Training

All three scanner models are trained from scratch on redistributable data.

Run the Python tests with uv run pytest -q.

License

Project code is Apache-2.0.

Metadata

Release files for flattener-scan 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flattener-scan 1.1.0
File Size Uploaded
flattener_scan-1.1.0.tar.gz 5.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for flattener-scan 1.1.0
File Interpreter ABI Platform
flattener_scan-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.5 MB

Release files / flattener_scan-1.1.0.tar.gz

Download URL flattener_scan-1.1.0.tar.gz
Size 5.8 MB
Tags Source
SHA-256 checksum
How to use checksums
352ba5a14cb53b7eba2c166dc11bff1e8c95e402350944ddf1928eb479d16724
BLAKE2b-256 checksum
How to use checksums
1d7a270300e24ed5714173e313f23b250683f9494500f5c55f176ba857a80e7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / flattener_scan-1.1.0-py3-none-any.whl

Download URL flattener_scan-1.1.0-py3-none-any.whl
Size 5.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ec509bb3c521785146f5e5280cfa5f52de956a6d5af86c4f1546ffe3b116d3f1
BLAKE2b-256 checksum
How to use checksums
c1025e5ccb6dc6f69bbb7ff10239762f197622d43bbb55d176b4a47dfdf39bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release history Release notifications | RSS feed

1.1.1

2 release files

This release

1.1.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page