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.

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

The extra index installs the CPU build of PyTorch. Without it, pip on Linux installs 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.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.0.0
File Size Uploaded
flattener_scan-1.0.0.tar.gz 5.8 MB Details

Built distribution (wheel)

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

Total release size: 11.4 MB

Release files / flattener_scan-1.0.0.tar.gz

Download URL flattener_scan-1.0.0.tar.gz
Size 5.8 MB
Tags Source
SHA-256 checksum
How to use checksums
84ab56c2786cad800770fcc86245e413469049f3e06fa151b639fe55b2f56421
BLAKE2b-256 checksum
How to use checksums
8a237bf7ed21ec2b00ba70bd0e6627c506ebd37226d583d243fca5c84a14c8b4
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.0-py3-none-any.whl

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

1.0.1

2 release files

This release

1.0.0 This release

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