ArticleslgStudy

physics

HOCR

HOCR is a physics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand HOCR rather than just read about it. In short: hOCR is an open standard of data representation for formatted text obtained from optical character recognition (OCR). The definition encodes text, style, layout information, recognition confidence metrics and other information using Extensible Markup Language (XML) in the form of Hypertext Markup Language (HTML) or XHTML.

Key takeaways

  • HOCR belongs to physics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect HOCR to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of HOCR from memory before moving on to harder problems.

Reference excerpt

hOCR is an open standard of data representation for formatted text obtained from optical character recognition (OCR). The definition encodes text, style, layout information, recognition confidence metrics and other information using Extensible Markup Language (XML) in the form of Hypertext Markup Language (HTML) or XHTML.

Software The following OCR software can output the recognition result as hOCR file:

OCRopus Tesseract Cuneiform ghostscript HebOCR gcv2hocr gImageReader

Example The following example is an extract of an hOCR file:

The recognized text is stored in normal text nodes of the HTML file. The distribution into separate lines and words is here given by the surrounding span tags. Moreover, the usual HTML entities are used, for example the p tag for a paragraph. Additional information is given in the properties such as:

different layout elements such as "ocr_par", "ocr_line", "ocrx_word" geometric information for each element with a bounding box "bbox" language information "lang" some confidence values "x_wconf"

bbox

General The Layout of the Bounding Box Object or bbox Object is Grammar.

property-name = "bbox" property-value = uint uint uint uint

Example bbox 0 0 100 200

The bbox - short for "bounding box" - of an element is a rectangular box around this element, which is defined by the upper-left corner (x0, y0) and the lower-right corner (x1, y1). the values are with reference to the top-left corner of the document image and measured in pixels the order of the values are x0 y0 x1 y1 = "left top right bottom"

Usage Use x_bboxes below for character bounding boxes. Do not use bbox unless the bounding box of the layout component is, in fact, rectangular, some non-rectangular layout components may have rectangular bounding boxes if the non-rectangularity is caused by floating elements around which text flows.

The bounding box bbox of this line is shown in blue and it is span by the upper-left corner (10, 20) and the lower-right corner (160, 30). All coordinates are measured with reference to the top-left corner of the document image which border is drawn in black.

Searchable PDF files The hOCR format is most commonly used to make searchable PDF files or as an extracted metadata of the PDF file. To create searchable PDF files, one can use the following open-source tools to create a scanned document image and a .hocr file of the particular image.

hocr-tools Source: hocr-tools is an open source library written in Python. It has a command-line utility attached in the scripts called hocr-pdf that enables us to convert standard hocr files to a searchable PDF file. It is also worth noting that the version for dealing with hocr files in RTL or non-Latin scripts like Arabic, we need to use the GitHub repository at the moment. hocr-pdf We can use the hocr-pdf utility using the following basic syntax.

hocr-pdf—savefile final.pdf folder_images_and_hocr

The folder_images_and_hocr must contain the respective .jpg and .hocr format files with their file extensions changed.

Known issues Some of the known issues of hocr-pdf script in PyPI installation are the following.

Not up to date with GitHub repository. hocr-pdf is broken on line 134 due to decodebytes() depreciated after Python 3.1

Known fixes Compile hocr-tools using latest GitHub repository.

hocr2pdf hocr2pdf is another library that supports the conversion of hocr files. It is written in C++ and is cross-compatible with other libraries. It also has support for UTF-8 languages but that may require some additional debugging and browsing through some google conversation records to achieve that.

According to Ubuntu Manpages,ExactImage is a fast C++ image processing library. Unlike many other library frameworks it allows operation in several color spaces and bit depths natively, resulting in low memory and computational requirements. hocr2pdf creates well layouted, searchable PDF files from hOCR (annotated HTML) input obtained from an OCR system.

hOCR to PDF attempts In addition to the following discussed and stable libraries there have been many contributions to the hOCR format over the years with support from many of the early adopters of this format. You can get access to inlaying text on an Image with hOCR and converting that in a PDF file using Python 2 with this 12-year-old script as of 2021. This script can also be updated and made functional by converting that Python 2 Source code to Python 3 Supported Context. - HOCRConverter by jbrinley (Documentation)

HOCRConverter The HOCRConverter is a script written in Python 2.x that can used in order to convert a hOCR file with a specified image file in order to convert it to a searchable PDF file. You can see the documentation using the link above.

Known issues Has not been tested. Does not natively support Python 3.x

See also ALTO (XML) — another OCR data representation format

References

External links The hOCR Specification for depth about hOCR. specification of current version (1.2 as of February 2021) hocr-tools – tools for manipulating and evaluating the hOCR format on GitHub ocr-fileformat – Software that validates and transforms various OCR file formats including hOCR on GitHub

Worked examples

Example 1 — a first encounter with HOCR

Start with the simplest possible case. Write down what HOCR claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In physics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to HOCR before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about HOCR ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of HOCR

In research
HOCR appears in physics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses HOCR in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
HOCR is common in secondary-school and first-year university syllabi. It links to neighbouring topics Microformats, Optical character recognition, so understanding it makes those chapters shorter.
In everyday life
Look for HOCR outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study HOCR in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what HOCR means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain HOCR out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is HOCR in simple terms?

hOCR is an open standard of data representation for formatted text obtained from optical character recognition (OCR). The definition encodes text, style, layout information, recognition confidence metrics and other information using Extensible Markup Language (XML) in the form of Hypertext Markup L…

Why does HOCR matter?

Because it connects several physics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study HOCR?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on HOCR.

Tags

  • Microformats
  • Optical character recognition

Keep exploring