ocr/README.md

84 lines
3.0 KiB
Markdown
Raw Normal View History

2021-02-19 13:04:03 +01:00
# OCR - Optical Character Recognition
2019-04-02 15:43:41 +02:00
2021-02-19 13:04:03 +01:00
This software implements a heavily parallelized pipeline to recognize text in PDF files. It is used for nopaque's OCR service but you can also use it standalone, for that purpose a convenient wrapper script is provided.
2019-04-02 15:43:41 +02:00
2021-02-19 13:04:03 +01:00
## Software used in this pipeline implementation
- Official Debian Docker image (buster-slim) and programs from its free repositories: https://hub.docker.com/_/debian
- ocropy (1.3.3): https://github.com/ocropus/ocropy/releases/tag/v1.3.3
- pyFlow (1.1.20): https://github.com/Illumina/pyflow/releases/tag/v1.1.20
- Tesseract OCR (4.1.1): https://github.com/tesseract-ocr/tesseract/releases/tag/4.1.1
- tessdata_best (4.1.0): https://github.com/tesseract-ocr/tessdata_best/releases/tag/4.1.0
2019-05-16 13:22:29 +02:00
2019-04-02 15:43:41 +02:00
2021-02-19 13:04:03 +01:00
## Use this image
2019-05-16 13:22:29 +02:00
2021-02-19 13:04:03 +01:00
1. Create input and output directories for the pipeline.
``` bash
mkdir -p /<my_data_location>/input /<my_data_location>/output
2019-05-16 13:17:15 +02:00
```
2019-04-02 15:43:41 +02:00
2021-02-19 13:04:03 +01:00
2. Place your PDF files inside `/<my_data_location>/input`. Files should all contain text of the same language.
2019-04-02 15:43:41 +02:00
2021-02-19 13:04:03 +01:00
3. Start the pipeline process. Check the [Pipeline arguments](#pipeline-arguments) section for more details.
2019-05-16 13:17:15 +02:00
```
2021-02-19 13:04:03 +01:00
# Option one: Use the wrapper script
## Install the wrapper script (only on first run). Get it from https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr/-/raw/1.0.0/wrapper/ocr, make it executeable and add it to your ${PATH}
cd /<my_data_location>
2021-02-23 11:11:50 +01:00
ocr -i input -l <language_code> -o output <optional_pipeline_arguments>
2019-04-02 15:43:41 +02:00
2021-02-19 13:04:03 +01:00
# Option two: Classic Docker style
2019-04-02 15:43:41 +02:00
docker run \
2019-05-16 13:17:15 +02:00
--rm \
-it \
2019-06-03 13:32:42 +02:00
-u $(id -u $USER):$(id -g $USER) \
2021-02-19 13:04:03 +01:00
-v /<my_data_location>/input:/input \
-v /<my_data_location>/output:/output \
gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:1.0.0 \
2019-06-02 21:38:30 +02:00
-i /input \
2021-02-19 13:04:03 +01:00
-l <language_code>
-o /output \
<optional_pipeline_arguments>
2019-04-02 15:43:41 +02:00
```
2019-05-20 12:06:57 +02:00
2021-02-19 13:04:03 +01:00
4. Check your results in the `/<my_data_location>/output` directory.
```
2019-05-16 13:17:15 +02:00
2021-02-19 13:04:03 +01:00
### Pipeline arguments
2019-05-16 13:17:15 +02:00
`-l languagecode`
* Tells tesseract which language will be used.
2021-02-23 11:11:50 +01:00
* options = ara (Arabic), chi_tra (Chinese - Traditional), dan (Danish), deu (German), ell (Greek, Modern (1453-)), eng (English), enm (Middle englisch), fra (French), frk (German Fraktur), frm (Middle french), ita (Italian), por (Portuguese), rus (Russian), spa (Spanish)
2019-05-16 13:17:15 +02:00
* required = True
`--keep-intermediates`
* If set, all intermediate files created during the OCR process will be
kept.
* default = False
* required = False
`--nCores corenumber`
* Sets the number of CPU cores being used during the OCR process.
* default = min(4, multiprocessing.cpu_count())
* required = False
2019-05-16 13:26:19 +02:00
`--skip-binarisation`
2019-05-17 01:07:39 +02:00
* Used to skip binarization with ocropus. If skipped, only the tesseract binarization is used.
2019-05-16 13:17:15 +02:00
* default = False
2019-04-16 11:16:35 +02:00
2021-02-19 13:04:03 +01:00
``` bash
# Example with all arguments used
2019-05-16 13:17:15 +02:00
docker run \
--rm \
-it \
2019-06-03 13:32:42 +02:00
-u $(id -u $USER):$(id -g $USER) \
2021-02-19 13:04:03 +01:00
-v "$HOME"/ocr/input:/input \
-v "$HOME"/ocr/output:/output \
gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:1.0.0 \
2019-06-02 21:38:30 +02:00
-i /input \
2019-05-16 13:17:15 +02:00
-l eng \
2019-06-02 21:38:30 +02:00
-o /output \
2019-05-16 13:17:15 +02:00
--keep_intermediates \
--nCores 8 \
2019-05-16 13:26:19 +02:00
--skip-binarisation
2019-05-16 13:17:15 +02:00
```