kraken¶
kraken is a turn-key OCR system optimized for historical and non-Latin script material.
Features¶
kraken’s main features are:
Fully trainable layout analysis, reading order, and character recognition
Right-to-Left, BiDi, and Top-to-Bottom script support
ALTO, PageXML, abbyyXML, and hOCR output
Word bounding boxes and character cuts
Multi-script recognition support
Public repository of model files
Pull requests and code contributions are always welcome.
Installation¶
Kraken can be run on Linux or Mac OS X (both x64 and ARM). Installation through the on-board pip utility and the anaconda scientific computing python are supported.
Installation using Pip¶
$ pip install kraken
or by running pip in the git repository:
$ pip install .
If you want direct PDF and multi-image TIFF/JPEG2000 support it is necessary to install the pdf extras package for PyPi:
$ pip install kraken[pdf]
or
$ pip install .[pdf]
respectively.
Development Branch Installation using Conda¶
To install the latest development branch through conda clone the kraken git repository and install with the provided environment files:
$ git clone https://github.com/mittagessen/kraken.git
$ cd kraken
$ conda env create -f environment.yml
or:
$ git clone https://github.com/mittagessen/kraken.git
$ cd kraken
$ conda env create -f environment_cuda.yml
for CUDA acceleration with the appropriate hardware.
Finding Recognition Models¶
Finally you’ll have to scrounge up a model to do the actual recognition of characters. To download the default model for printed French text and place it in the kraken directory for the current user:
$ kraken get 10.5281/zenodo.10592716
A list of libre models available in the central repository can be retrieved by running:
$ kraken list
Model metadata can be extracted using:
$ kraken show 10.5281/zenodo.10592716
name: 10.5281/zenodo.10592716
CATMuS-Print (Large, 2024-01-30) - Diachronic model for French prints and other languages
<p><strong>CATMuS-Print (Large) - Diachronic model for French prints and other West European languages</strong></p>
<p>CATMuS (Consistent Approach to Transcribing ManuScript) Print is a Kraken HTR model trained on data produced by several projects, dealing with different languages (French, Spanish, German, English, Corsican, Catalan, Latin, Italian…) and different centuries (from the first prints of the 16th c. to digital documents of the 21st century).</p>
<p>Transcriptions follow graphematic principles and try to be as compatible as possible with guidelines previously published for French: no ligature (except those that still exist), no allographetic variants (except the long s), and preservation of the historical use of some letters (u/v, i/j). Abbreviations are not resolved. Inconsistencies might be present, because transcriptions have been done over several years and the norms have slightly evolved.</p>
<p>The model is trained with NFKD Unicode normalization: each diacritic (including superscripts) are transcribed as their own characters, separately from the "main" character.</p>
<p>This model is the result of the collaboration from researchers from the University of Geneva and Inria Paris and will be consolidated under the CATMuS Medieval Guidelines in an upcoming paper.</p>
scripts: Latn
alphabet: !"#$%&'()*+,-./0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz|}~¡£¥§«¬°¶·»¿ÆßæđłŒœƀǝɇΑΒΓΔΕΖΘΙΚΛΜΝΟΠΡΣΤΥΦΧΩαβγδεζηθικλμνξοπρςστυφχωϛחלרᑕᗅᗞᚠẞ–—‘’‚“”„‟†•⁄⁊⁋℟←▽◊★☙✠✺✻⟦⟧⬪ꝑꝓꝗꝙꝟꝯꝵ SPACE, COMBINING GRAVE ACCENT, COMBINING ACUTE ACCENT, COMBINING CIRCUMFLEX ACCENT, COMBINING TILDE, COMBINING MACRON, COMBINING DOT ABOVE, COMBINING DIAERESIS, COMBINING RING ABOVE, COMBINING COMMA ABOVE, COMBINING REVERSED COMMA ABOVE, COMBINING CEDILLA, COMBINING OGONEK, COMBINING GREEK PERISPOMENI, COMBINING GREEK YPOGEGRAMMENI, COMBINING LATIN SMALL LETTER I, COMBINING LATIN SMALL LETTER U, 0xe682, 0xe68b, 0xe8bf, 0xf1a7
accuracy: 98.56%
license: cc-by-4.0
author(s): Gabay, Simon; Clérice, Thibault
date: 2024-01-30
Quickstart¶
The structure of an OCR software consists of multiple steps, primarily preprocessing, segmentation, and recognition, each of which takes the output of the previous step and sometimes additional files such as models and templates that define how a particular transformation is to be performed.
In kraken these are separated into different subcommands that can be chained or ran separately:
Recognizing text on an image using the default parameters including the prerequisite step of page segmentation:
$ kraken -i image.tif image.txt segment -bl ocr -m catmus-print-fondue-large.mlmodel
Loading RNN ✓
Processing ⣻
To segment an image into reading-order sorted baselines and regions:
$ kraken -i bw.tif lines.json segment -bl
To OCR an image using the previously downloaded model:
$ kraken -i bw.tif image.txt segment -bl ocr -m catmus-print-fondue-large.mlmodel
To OCR an image using the default model and serialize the output using the ALTO template:
$ kraken -a -i bw.tif image.txt segment -bl ocr -m catmus-print-fondue-large.mlmodel
All commands and their parameters are documented, just add the standard
--help
flag for further information.
Training Tutorial¶
There is a training tutorial at Training kraken.
License¶
Kraken
is provided under the terms and conditions of the Apache 2.0
License.
Funding¶
kraken is developed at the École Pratique des Hautes Études, Université PSL.
This project was partially funded through the RESILIENCE project, funded from the European Union’s Horizon 2020 Framework Programme for Research and Innovation.