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 on Linux, 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 next to each scan, or --json to print a one-line summary per page.
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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flattener_scan-1.1.1.tar.gz | 5.8 MB | Without provenance | Details for flattener_scan-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flattener_scan-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for flattener_scan-1.1.1-py3-none-any.whl |
Total release size: 11.5 MB
Release files / flattener_scan-1.1.1.tar.gz
| Download URL | flattener_scan-1.1.1.tar.gz |
|---|---|
| Size | 5.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76bb627323b7f9308ae7ef4cdd18827c9fa033e0e7ac388ec60867ff18849de9
|
|
BLAKE2b-256 checksum How to use checksums |
745e093b13b15ef19f8aba1225eaf089fa2afcbf155fae0ddd92442aa98214d9
|
| 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.1-py3-none-any.whl
| Download URL | flattener_scan-1.1.1-py3-none-any.whl |
|---|---|
| Size | 5.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8537761d9cde54b7487af2737634bb56df03600312f43065f78e84297ba5a030
|
|
BLAKE2b-256 checksum How to use checksums |
143eb9fb9afeeaead7dadf11238a3b85fdbd52b568dbf94231c6426552cfebd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for flattener-scan 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.