Folio Orient: auto-rotation and deskewing model for scans
2 min readupdated
Folio Orient detects the rotation angle of a page scan and corrects skew so that the text is oriented vertically. A lightweight ONNX model (422 KiB) analyzes small text fragments to determine the required 90-degree rotation, while a projection algorithm measures minor tilt within ±8°. Both stages run on a standard CPU and can be used completely offline. This solution is useful for automating document scanning and archive digitization.
Key features
- Two-stage correction: determines coarse rotation at 0, 90, 180, or 270 degrees and fine tilt.
- Lightweight: the ONNX model size is only 422 KiB, running locally on a CPU.
- High accuracy: on a test dataset of historical scans, the correct rotation was determined in 98.5% of cases.
- Error protection: a low confidence threshold (less than 0.70) preserves the original orientation for non-standard layouts.
What you can do
- Batch scan processing: run a script via CLI to automatically straighten a library of scanned documents.
- Python integration: use the PageOrienter class and the correct function in custom image processing pipelines.
- Archive digitization: prepare old books and documents before optical character recognition (OCR).
Example
from PIL import Image
from folio_orient import PageOrienter, correct
orienter = PageOrienter()
with Image.open("examples/scan.jpg") as page:
estimate = orienter.estimate(page)
print(estimate)
upright = correct(page, estimate)
upright.save("corrected.png")
Read more
DetailsBenchmarks: 98.5% correct predictions on historical test scans.
Hardware: runs on CPU, requires minimal VRAM/RAM.
Limitations: not tested on handwritten text, vertical writing, or receipts.
Training: trained on synthetic fonts using 13 Google Fonts families.










Comments