Lightweight, pure-OpenCV document deskewing and orientation correction — no deep learning required.
Project description
uprightKit
Lightweight, pure-OpenCV document deskewing and orientation correction. No deep learning, no model downloads, no GPU — just classical computer vision (Hough transform + edge-density profiling).
It fixes two common problems with scanned/photographed documents:
- Fine skew — the page is tilted a few degrees.
- 180-degree flips — the page was scanned/photographed upside down.
Install
pip install uprightkit
# with PDF support:
pip install uprightkit[pdf]
Usage
Single image
import uprightkit
uprightkit.fix_image("scan.jpg", output_path="scan_fixed.jpg")
PDF (page by page)
import uprightkit
uprightkit.fix_pdf("document.pdf", output_path="document_fixed.pdf")
Already have a numpy array (e.g. in an existing OpenCV pipeline)?
import cv2
import uprightkit
image = cv2.imread("scan.jpg")
fixed = uprightkit.fix_array(image) # returns a numpy array, BGR
Command line
uprightkit scan.jpg scan_fixed.jpg
uprightkit document.pdf document_fixed.pdf
uprightkit scan.jpg scan_fixed.jpg --no-flip-fix # skip the 180-degree check
Tuning
The 180-degree flip detector assumes a correctly-oriented page has more text/content density near the top half than the bottom half. This holds for many ID cards, forms, and letters — but not for every document layout. If you get incorrect flips on your documents, disable it:
uprightkit.fix_image("scan.jpg", output_path="out.jpg", correct_180_flip=False)
Other tunable parameters (skew_angle_tolerance, flip_density_ratio,
hough_threshold, min_line_length, max_line_gap) are documented in the
docstring of uprightkit.fix_skew_and_orientation.
Why no deep learning?
This is intentionally a fast, dependency-light tool meant for preprocessing pipelines (e.g. before OCR) where you don't want to pull in a multi-hundred-MB model or pay GPU inference cost just to straighten a page.
License
MIT --- see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uprightkit-0.1.0.tar.gz.
File metadata
- Download URL: uprightkit-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
835a4a2fd8bf2960767d8708a3a5fbc865b2a78a37928333e07b0b75a44c2eec
|
|
| MD5 |
2d73835c9160e69f50e080feff1d9799
|
|
| BLAKE2b-256 |
fcd482025fe2c1632ce0fe331f3ef17b98210931566797b672acffd26595f96c
|
File details
Details for the file uprightkit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: uprightkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f1f4d5a12c7285e2e808c9267fa78bca7c27f1ec5a70e384f3964ef2df82c4f
|
|
| MD5 |
e0af1e5f89a90171d83ef8796127b047
|
|
| BLAKE2b-256 |
b3ea5756f3b83af8a350b7bd0b6a74d6762c0063b3fad2a7b21aa685276aed95
|