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

Flattener needs Python 3.12 and is tested on Linux x86_64 with CPU PyTorch.

uvx --torch-backend cpu flattener-scan photo.jpg --out scans

Or install it with pip:

pip install flattener-scan --extra-index-url https://download.pytorch.org/whl/cpu
flattener photo.jpg --out scans

--torch-backend cpu and the extra index install the CPU build of PyTorch. Without them, Linux gets the CUDA build, which is several gigabytes larger.

To work from a clone of this repository, use uv sync --python 3.12 and run uv run flattener.

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

Pass multiple photos for a batch. Results include an image and a .scan.json record with outcomes and timings. Book spreads produce separate page files. Use --region, --quad, --quarter or --output-size for manual control; run flattener --help for all options.

From Python:

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

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

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

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.0.1

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.0.1
File Size Uploaded
flattener_scan-1.0.1.tar.gz 5.8 MB Details

Built distribution (wheel)

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

Total release size: 11.4 MB

Release files / flattener_scan-1.0.1.tar.gz

Download URL flattener_scan-1.0.1.tar.gz
Size 5.8 MB
Tags Source
SHA-256 checksum
How to use checksums
0a558766387f77a3b1405d309d49776a527c8eba646d77c33486a76fd9214001
BLAKE2b-256 checksum
How to use checksums
f280bd17457820ccac6d8c62cfe6489c4efd088065e28cc4633658238f5d869f
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.0.1-py3-none-any.whl

Download URL flattener_scan-1.0.1-py3-none-any.whl
Size 5.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4aaa5befc3432ff16afbd98011a97fed1faaf15ca051fd3724073c42800a3e7e
BLAKE2b-256 checksum
How to use checksums
f7e3b954978deddca266b11bb28d882d6b7e33d0ca0d4e86a99f42118558088e
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

1.1.0

2 release files

This release

1.0.1 This release

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