Skip to main content

OCR Util

python-app Coverage PyPi version PyPI - Downloads PyPI - License PyPI - Python Version

Collection of utils for

  • evaluation of OCR data for the masses
  • generation of extended OCR-Evaluation Corpora
  • generation of pair-wise Trainingdata for OCR-Backends

Requirements

  • recent *nix-OS
  • Python3.10+ Environment

Usage

Each section contains detailed usage help instructions:

# evaluation
ocr-util eval --help

# corpus management
ocr-util corpus --help

# analyse an existing METS corpus
ocr-util corpus-analyse --help

# slice image by image + input OCR
ocr-util slice --help

# render image + input OCR
ocr-util show --help

Data problems

Inconsistent OCR Groundtruth with empty texts (ALTO String elements missing CONTENT or PAGE without TextEquiv) or invalid geometrical coordinates (less than 3 points or even empty) will lead to evaluation errors if geometry must be respected.

Please note:
Invalid data files are excluded and reported where possible from evaluation.
The term 'invalid' refers to errors in schemas in structured XML-data, i.e. syntax errors and further if included geometrical information includes inconsistencies like missing points or missmatching shapes.

Evaluation Filter-Then-Aggregate

The evaluation CLI supports a single pre-aggregation filter using metadata extractors.

Example: keep only entries where MODS language is exactly German, then aggregate by publication century:

ocr-util eval <candidates> \
	--reference <groundtruth> \
	--mets-file <mets.xml> \
	--filter-by "mods:language=ger" \
	--aggregate-by "mods:dateIssued:century"

Multi-language filter values are interpreted as sets:

ocr-util eval <candidates> \
	--reference <groundtruth> \
	--mets-file <mets.xml> \
	--filter-by "mods:language=ger+eng" \
	--aggregate-by "mods:dateIssued:century"

Behavior:

  • single filter value -> exact match (e.g. ger does not match ger+eng)
  • multi-value filter -> all filter values must be present in any order
  • entries missing the filter criterion are reported as WARNING and discarded
  • METS coverage reports how many evaluation pairs map to full-text references and how many METS references have no evaluation pair
  • aggregation coverage reports how many evaluated pairs provide each dimension; reported items count candidate/ground-truth pairs, not MODS elements

Corpus Analysis

Existing METS corpora can be filtered without evaluation candidate data. Matching full-text file references are printed one per line:

ocr-util corpus-analyse <mets.xml> \
	--filter-by "mods:dateIssued:century=16th"

Repeat --filter-by to combine criteria with AND:

ocr-util corpus-analyse <mets.xml> \
	--filter-by "mods:dateIssued:century=16th" \
	--filter-by "mods:language=ger"

Check that every local file referenced by any METS FLocat exists:

ocr-util corpus-analyse <mets.xml> --check

Relative paths are resolved from the METS directory. Missing files and remote references that cannot be checked locally produce a non-zero exit status. This is a file-presence check; it does not perform XML schema validation.

Development

Platform: Intel(R) Core(TM) i5-6500 CPU@3.20GHz, 16GB RAM, Ubuntu 22.04 LTS, Python 3.10+

# clone local
git clone <repository-url> <local-dir>
cd <local-dir>

# enable virtual python 3 environment (linux)
# and update pip itself
python3.10 -m venv venv
. venv/bin/activate
python -m pip install -U pip

# install with dev dependencies
python -m pip install -e ".[dev,test]"

# run tests with coverage
python -m pytest --cov=src

# run tests faster (parallel, auto worker count)
python -m pytest -q -n auto

Contribution

Contributions, suggestions and proposals welcome!

License

Under terms of the MIT license.

NOTE: This software depends on packages that might be licensed under different terms.

Metadata

Release files for ocr-util 2.2.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-util 2.2.1
File Size Uploaded Provenance Actions
ocr_util-2.2.1.tar.gz 124.6 kB Without provenance Details for ocr_util-2.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ocr-util 2.2.1
File Interpreter ABI Platform Actions
ocr_util-2.2.1-py3-none-any.whl Python 3 none any Details for ocr_util-2.2.1-py3-none-any.whl

Total release size: 217.4 kB

Release files / ocr_util-2.2.1.tar.gz

Download URL ocr_util-2.2.1.tar.gz
Size 124.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a6be9c4d090aa578b8dc1ed6f48be844ef8e959042bff5f55bfa8b45c5023c9e
BLAKE2b-256 checksum
How to use checksums
b84238e4b6cb31af34bd77e1ce97594747af0c7ab2fd079e88aa9777d46e3bba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / ocr_util-2.2.1-py3-none-any.whl

Download URL ocr_util-2.2.1-py3-none-any.whl
Size 92.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de1b86a91d9697a738b0c2e95cb0c6b1031dd23e5ecab5204a168506f691fed3
BLAKE2b-256 checksum
How to use checksums
4c41bf2ff2576df07388caea907702c3fe1d801f48e50567ab0c4f2a17b04016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

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