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.0.

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.0

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

Built distribution (wheel)

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

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

Download URL ocr_harness-1.1.0-py3-none-any.whl
Size 47.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
431dbbe7e66b4668dd780f359928c8d5532888d6fe0c76173283b25c27c7f228
BLAKE2b-256 checksum
How to use checksums
5b8d0cafb7b65ae86b3261cc9a9199ef93b2a62607f8e2d33e259f2b6024e60b
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.0

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