How sbrunner/deskew works
Project Type and Purpose
• Type: A small, single-module Python library + CLI tool for skew detection and correction in text-containing images.
• Purpose: Provide both a programmatic API (determine_skew) and a command-line utility (deskew) to compute and apply deskew rotations, with optional debug-image generation.
File Structure
• Top-level package: deskew/
• __init__.py: exposes determine_skew (core algorithm) and debug variants
• cli.py: command-line entry point
• Supporting files:
• pyproject.toml, README.md, LICENSE (packaging, docs)
• tests/: automated tests for core functionality
• doc/: sample input/output images
• .github/, ci/: CI pipelines & automation
• No external microservices—pure local execution.
README for Additional Insights
• Two main usage modes:
a) CLI (“deskew input.png”), optional --output
b) Library (import, call determine_skew, pass result to a rotate function from skimage/OpenCV)
• Optional debug-image generation when installed with extras.
• Underlying dependencies: NumPy, scikit-image or OpenCV.
Main Components & Interactions
a. Components:
1. User Interface
– CLI (deskew command)
– Library API (determine_skew, determine_skew_debug_images)
2. Core Algorithm
– Skew detection logic (Hough transform, peak detection)
– Parameterization (num_peaks, min_angle, etc.)
3. Image I/O & Processing
– Read image (via scikit-image or OpenCV)
– Convert to grayscale
– Compute skew angle
– Rotate image (using transform/warp functions)
– Write output image
4. Packaging & Distribution
– pyproject.toml, PyPI pipeline
5. Testing & CI
– Unit tests (tests/test_deskew.py)
– GitHub Actions workflows (.github/workflows)
– Pre-commit hooks (.pre-commit-config.yaml)
b. Relationships/Flow:
– User invokes CLI → CLI parses args → calls library core → library loads image → detection pipeline → returns angle → rotation pipeline → writes output → CLI returns exit code.
– Library API clients follow same core pipeline sans CLI parsing.
– Tests exercise core logic and CLI wrapper.
– CI pipelines build, test, lint, and publish package.
c. Architectural Patterns & Principles
– Single Responsibility: CLI logic separated from core algorithm
– Modular layering:
Layer-1: Interface (CLI / API)
Layer-2: Core algorithm (detection + debug)
Layer-3: I/O & image manipulation
– Dependency Injection: algorithm parameters pluggable via function arguments
d. Key Technologies & Libraries
– Python 3.x, NumPy
– scikit-image (default) or OpenCV (alternative)
– Click or argparse (CLI parsing)
– pytest (testing)
– GitHub Actions (CI/CD)
Elements
• “CLI Entry Point”
• “Library API”
• “Skew Detection Engine”
• “Image I/O & Rotation Module”
• “Debug-Image Generator”
• “Third-Party Libraries”
• “Unit Tests”
• “CI/CD Pipelines”
• From User → CLI/API → Skew Engine → Rotation → Filesystem
• Tests → Core & CLI
• CI → Code Repository → PyPI
• API/CLI = blue rectangles
• Core algorithm = green octagon
• Tests/CI = yellow parallelograms