Skip to main content

Implementation of the hOCR specs

Project description


Validation of hOCR close to the specs


hOCR is a flavor of HTML for encoding the results of Optical Character Recognition (OCR) engines. It is supported by most OCR engines, such as tesseract, ocropus/ocropy and kraken.

The hOCR specifications is at the same time very simple (hOCR is just HTML) and hard to implement, due to its terseness and lack of up-to-date code samples. This project aims to implement the rules defined by the specs from the ground up to serve as a validation tool and reference implementation. It is meant to help hOCR implementers and support tools like hocr-tools.


Use pip:

# System-wide:
sudo pip install [--user] hocr-spec
# For current user:
pip install --user hocr-spec

From source:

git clone
cd hocr-spec-python
# System-wide:
sudo python install
# For current user:
python install --user

Command line interface

usage: hocr-spec [-h] [--format {text,bool,ansi,xml}]
                 [--profile {relaxed,standard}]
                 [--implicit_capabilities CAPABILITY]
                 [--skip-check {attributes,classes,metadata,properties}]
                 [--parse-strict] [--silent]
                 sources [sources ...]

positional arguments:
  sources               hOCR file to check or '-' to read from STDIN

optional arguments:
  -h, --help            show this help message and exit
  --format {text,bool,ansi,xml}, -f {text,bool,ansi,xml}
                        Report format
  --profile {relaxed,standard}, -p {relaxed,standard}
                        Validation profile
  --implicit_capabilities CAPABILITY, -C CAPABILITY
                        Enable this capability. Use '*' to enable all
                        capabilities. In addition to the 'ocr*' classes, you
                        can use ['ocrp_dir', 'ocrp_font', 'ocrp_lang',
                        'ocrp_nlp', 'ocrp_poly']
  --skip-check {attributes,classes,metadata,properties}, -X {attributes,classes,metadata,properties}
                        Skip one check
  --parse-strict        Parse HTML with less tolerance for errors
  --silent, -s          Don't produce any output but signal success with exit

API example

from hocr_spec import HocrValidator

validator = HocrValidator()
report = validator.validate('/path/to/sample.hocr')
# <report valid='false'>...</report>

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

hocr-spec-0.2.0.tar.gz (12.8 kB view hashes)

Uploaded Source

Built Distribution

hocr_spec-0.2.0-py2.py3-none-any.whl (13.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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