Skip to main content

Document image orientation detection and correction using projection profile analysis and optional Tesseract OSD.

Project description

docorient

Document image orientation detection and correction.

Detects and fixes rotation (0°, 90°, 180°, 270°) in scanned document images using projection profile analysis and optional Tesseract OSD.

Installation

pip install docorient

For 180° detection via Tesseract OSD:

pip install docorient[ocr]

Note: The [ocr] extra requires Tesseract installed on your system.

Quick Start

Detect orientation

from PIL import Image
from docorient import detect_orientation

image = Image.open("document.jpg")
result = detect_orientation(image)

print(result.angle)     # 0, 90, 180, or 270
print(result.method)    # detection method used
print(result.reliable)  # confidence flag

Correct a single image

from docorient import correct_image

corrected = correct_image(image)
corrected.save("fixed.jpg")

Correct with metadata

from docorient import correct_image

result = correct_image(image, return_metadata=True)
print(result.orientation.angle)
result.image.save("fixed.jpg")

Correct multi-page document (majority voting)

from docorient import correct_document_pages

pages = [Image.open(f"page_{i}.jpg") for i in range(5)]
corrected_pages = correct_document_pages(pages)

Batch process a directory

from docorient import process_directory, OrientationConfig

config = OrientationConfig(workers=4, output_quality=95)
summary = process_directory("./scans", output_dir="./fixed", config=config)

print(f"Corrected: {summary.corrected}/{summary.total_pages}")

CLI

docorient ./scans --output ./fixed --workers 4
docorient ./scans --dry-run
docorient ./scans --no-ocr --limit 100

How It Works

  1. Projection profile analysis detects 90° and 270° rotations by comparing horizontal vs vertical text energy
  2. Tesseract OSD (optional) detects 180° rotation with confidence thresholding
  3. Majority voting across pages of the same document improves reliability

Supported Formats

Any format readable by Pillow: JPEG, PNG, TIFF, BMP, GIF, WebP, and more.

Configuration

from docorient import OrientationConfig

config = OrientationConfig(
    osd_confidence_threshold=2.0,
    output_quality=92,
    max_osd_dimension=1200,
    projection_target_dimension=800,
    workers=4,
    resume_enabled=True,
)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docorient-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docorient-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file docorient-0.1.0.tar.gz.

File metadata

  • Download URL: docorient-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for docorient-0.1.0.tar.gz
Algorithm Hash digest
SHA256 53f77569983db2ed5d9edea95861647fceabec1eecdcbf9b97d7506958475f07
MD5 bd35e19af4be6c7925d697f1a7decd76
BLAKE2b-256 1281535484426562c3022f6d2298492ba91a0e867b3b61043dc1d3763c5bbff3

See more details on using hashes here.

File details

Details for the file docorient-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: docorient-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for docorient-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53fb22e48310fec7cad7c32abf39e9b6eecec2929c1925e2d63c027297fe5a17
MD5 89c75af87f8607acac586fbd21695d6c
BLAKE2b-256 5bd394447f460cf70542d4859ee5b899666defa3084cd7cd70ce3b38056b33ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page