To install click the Add extension button. That's it.

The source code for the WIKI 2 extension is being checked by specialists of the Mozilla Foundation, Google, and Apple. You could also do it yourself at any point in time.

4,5
Kelly Slayton
Congratulations on this excellent venture… what a great idea!
Alexander Grigorievskiy
I use WIKI 2 every day and almost forgot how the original Wikipedia looks like.
Live Statistics
English Articles
Improved in 24 Hours
Added in 24 Hours
Languages
Recent
Show all languages
What we do. Every page goes through several hundred of perfecting techniques; in live mode. Quite the same Wikipedia. Just better.
.
Leo
Newton
Brights
Milds

From Wikipedia, the free encyclopedia

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.[1]

Software

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

Example

The following example is an extract of an hOCR file:

...
<p class="ocr_par" lang="deu" title="bbox930">
  <span class="ocr_line" title="bbox 348 797 1482 838; baseline -0.009 -6">
    <span class="ocrx_word" title="bbox 348 805 402 832; x_wconf 93">Die</span> 
    <span class="ocrx_word" title="bbox 421 804 697 832; x_wconf 90">Darlehenssumme</span> 
    <span class="ocrx_word" title="bbox 717 803 755 831; x_wconf 96">ist</span> 
    <span class="ocrx_word" title="bbox 773 803 802 831; x_wconf 96">in</span> 
    <span class="ocrx_word" title="bbox 821 803 917 830; x_wconf 96">ihrem</span> 
    <span class="ocrx_word" title="bbox 935 799 1180 838; x_wconf 95">ursprünglichen</span> 
    <span class="ocrx_word" title="bbox 1199 797 1343 832; x_wconf 95">Umfange</span> 
    <span class="ocrx_word" title="bbox 1362 805 1399 823; x_wconf 95">zu</span> 
    <span class="ocrx_word" title="bbox 1417 x_wconf 96">ver-</span> 
  </span>
  ...

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.

<span class="ocr_line" id="line_1" title="bbox 10 20 160 30"></span>

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.[3]

Searchable PDF files

The hOCR format is most commonly used in order to make searchable PDF files or as an extracted metadata of the PDF file. In order to create searchable PDF files we can use a scanned document image and a .hocr file of the particular image. We can use the following open source tools in order to achieve that.

hocr-tools

Source:[4]

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[5]

Known fixes

Compile hocr-tools using latest GitHub repository.

hocr2pdf

hocr2pdf[6] 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[7])

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.

from HocrConverter import HocrConverter


hocr = HocrConverter("myHocrFile.html")  # this can be done by changing .hocr to .html and vise-versa
hocr.to_text("output.txt")
hocr.to_pdf("myImageFile.png", "output.pdf")

Known issues

  • Has not been tested.
  • Does not natively support Python 3.x

See also

References

  1. ^ Breuel, T. (2007-09-01). "The hOCR Microformat for OCR Workflow and Results" (PDF). Ninth International Conference on Document Analysis and Recognition (ICDAR 2007) Vol 2. Vol. 2. pp. 1063–1067. doi:10.1109/ICDAR.2007.4377078. ISBN 978-0-7695-2822-9. S2CID 7565957.
  2. ^ "Ghostscript documentation". ghostscript.com. Retrieved March 1, 2024.
  3. ^ "hOCR - OCR Workflow and Output embedded in HTML". kba.cloud. Retrieved 18 December 2021.Public Domain This article incorporates text from this source, which is in the public domain.
  4. ^ ocropus, ocropus (2021-12-12). "hocr-tools". Github.
  5. ^ Ahmad, Muneeb (2021-12-12). "decodebytes() Depreciated in hocr-pdf use decodestring()". GitHub. Retrieved 2021-12-12. /home/muneeb/.local/bin/hocr-pdf:134: DeprecationWarning: decodestring() is a deprecated alias since Python 3.1, use decodebytes() uncompressed = bytearray(zlib.decompress(base64.decodestring(font)))
  6. ^ http://manpages.ubuntu.com/manpages/trusty/man1/hocr2pdf.1.html
  7. ^ Brinley, Jonathan (2009-04-02). "Convert hOCR to PDF". x+3. Archived from the original on 2021-02-06. Retrieved 2021-12-12.

External links

This page was last edited on 1 March 2024, at 11:26
Basis of this page is in Wikipedia. Text is available under the CC BY-SA 3.0 Unported License. Non-text media are available under their specified licenses. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. WIKI 2 is an independent company and has no affiliation with Wikimedia Foundation.