Skip to main content

OCR-Harness

OCR-Harness is a Python library for integrating OCR engines, applying image preprocessing, and evaluating recognition results against labeled data. Install the core library from PyPI, then add the OCR engines you need.

Current version: 1.1.1.

Features

  • An extensible OCR interface for implementing and registering OCR engines.
  • Evaluation metrics for character accuracy, word accuracy, word recall, word precision, and word count ratio, with per-image results, aggregate statistics, confidence intervals, and plotting utilities.
  • Image preprocessing for grid splitting, contour-based segmentation, and adaptive or Otsu binarization. The OCR interface maps detections from processed image regions back to the original image coordinates.
  • OCR result and configuration serialization, including configurable preprocessing steps and detection validators.
  • Optional wrappers for EasyOCR, PaddleOCR, and pytesseract.

Installation

Requires Python 3.12 or newer.

Install the core library:

pip install ocr-harness

Install with the optional OCR engines:

pip install "ocr-harness[ocrs]"

Pytesseract also requires the system Tesseract executable.

Run OCR from a config file

Save an engine configuration as config.json:

{
    "model_name": "EasyOCRModule",
    "model_params": {"languages": ["en"], "gpu": false},
    "preprocess_methods": [
        {"name": "grid_split_image", "kwargs": {"grid": [2, 2]}}
    ]
}

Load the configuration and run OCR on an RGB NumPy image:

from PIL import Image
import numpy as np

from ocr_harness.ocr_backbone import OCRAbstract
from ocr_harness.ocr_backbone.ocr_config import load_config
from ocr_harness.ocr_modules import import_all_modules

image = np.array(Image.open("image.png").convert("RGB"))

import_all_modules()
config = load_config("config.json")
ocr = OCRAbstract.from_config(config)
result = ocr.get_text_detections(image)

Install the ocrs extra to use the optional engine wrappers. Engine-specific system requirements still apply.

Add an OCR engine

Subclass OCRAbstract and implement _run_single to return an OCRResult:

import numpy as np

from ocr_harness.ocr_backbone import OCRAbstract, OCRConfig, OCRResult


class MyOCRModule(OCRAbstract):
    def __init__(self, config: OCRConfig | dict) -> None:
        super().__init__(config)
        # Initialize the OCR engine.

    def _run_single(self, image: np.ndarray, single_run_model_params: dict) -> OCRResult:
        # Return detections produced by the engine.
        ...

Subclasses register by class name and can be created with OCRAbstract.from_config.

License

MIT. See LICENSE.

Metadata

Release files for ocr-harness 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ocr-harness 1.1.1
File Size Uploaded Provenance Actions
ocr_harness-1.1.1.tar.gz 42.5 kB Without provenance Details for ocr_harness-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ocr-harness 1.1.1
File Interpreter ABI Platform Actions
ocr_harness-1.1.1-py3-none-any.whl Python 3 none any Details for ocr_harness-1.1.1-py3-none-any.whl

Total release size: 90.2 kB

Release files / ocr_harness-1.1.1.tar.gz

Download URL ocr_harness-1.1.1.tar.gz
Size 42.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6e6c937f56671f02df17e0a36fd22b2958956bcc9be09275790a6036ea69833c
BLAKE2b-256 checksum
How to use checksums
08c929cd683754a23475670afcd5c36ae30dbe36434d20a3c45e2388c59be939
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / ocr_harness-1.1.1-py3-none-any.whl

Download URL ocr_harness-1.1.1-py3-none-any.whl
Size 47.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa870dc2ce110bd769d2f7672a3257f9aa42694eb3fd677b1ac6ae46e41ff579
BLAKE2b-256 checksum
How to use checksums
4997c85e5f0647bbb7e0489bfbb8e35f621a5577e203ba5f21015f64f787ece9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for ocr-harness 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page