ocr/README.md

93 lines
3.0 KiB
Markdown
Raw Normal View History

2021-02-19 12:04:03 +00:00
# OCR - Optical Character Recognition
2019-04-02 13:43:41 +00:00
2021-02-19 12:04:03 +00: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 13:43:41 +00:00
2021-02-19 12:04:03 +00:00
## Software used in this pipeline implementation
- Official Debian Docker image (buster-slim): https://hub.docker.com/_/debian
- Software from Debian Buster's free repositories
2021-02-19 12:04:03 +00:00
- 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 11:22:29 +00:00
2021-02-19 12:04:03 +00:00
## Use this image
2019-05-16 11:22:29 +00:00
2021-02-19 12:04:03 +00:00
1. Create input and output directories for the pipeline.
``` bash
mkdir -p /<my_data_location>/input /<my_data_location>/output
2019-05-16 11:17:15 +00:00
```
2019-04-02 13:43:41 +00:00
2021-02-19 12:04:03 +00:00
2. Place your PDF files inside `/<my_data_location>/input`. Files should all contain text of the same language.
2019-04-02 13:43:41 +00:00
2021-02-19 12:04:03 +00:00
3. Start the pipeline process. Check the [Pipeline arguments](#pipeline-arguments) section for more details.
2019-05-16 11:17:15 +00:00
```
2021-02-19 12:04:03 +00: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/development/wrapper/ocr, make it executeable and add it to your ${PATH}
2021-02-19 12:04:03 +00:00
cd /<my_data_location>
2021-02-23 10:11:50 +00:00
ocr -i input -l <language_code> -o output <optional_pipeline_arguments>
2019-04-02 13:43:41 +00:00
2021-02-19 12:04:03 +00:00
# Option two: Classic Docker style
2019-04-02 13:43:41 +00:00
docker run \
2019-05-16 11:17:15 +00:00
--rm \
-it \
2019-06-03 11:32:42 +00:00
-u $(id -u $USER):$(id -g $USER) \
2021-02-19 12:04:03 +00:00
-v /<my_data_location>/input:/input \
-v /<my_data_location>/output:/output \
gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:development \
-i /ocr_pipeline/input \
-l <language_code> \
-o /ocr_pipeline/output \
2021-02-19 12:04:03 +00:00
<optional_pipeline_arguments>
2019-04-02 13:43:41 +00:00
```
2019-05-20 10:06:57 +00:00
2021-02-19 12:04:03 +00:00
4. Check your results in the `/<my_data_location>/output` directory.
2019-05-16 11:17:15 +00:00
2021-02-19 12:04:03 +00:00
### Pipeline arguments
2019-05-16 11:17:15 +00:00
#### Mandatory arguments
`-i, --input-dir INPUT_DIR`
* Input directory
`-o, --output-dir OUTPUT_DIR`
* Output directory
`-l, --language {spa,fra,dan,deu,eng,frm,chi_tra,ara,enm,ita,ell,frk,rus,por}`
* Language of the input (3-character ISO 639-2 language codes)
#### Optional arguments
`--binarize`
* Add binarization as a preprocessing step
`--log-dir`
* Logging directory
2019-05-16 11:17:15 +00:00
`--mem-mb`
* Amount of system memory to be used (Default: min(--n-cores * 2048, available system memory))
2019-05-16 11:17:15 +00:00
`--n-cores`
* Number of CPU threads to be used (Default: min(4, available CPU cores))
2019-05-16 11:17:15 +00:00
`-v, --version`
* Returns the current version of the OCR pipeline
2019-04-16 09:16:35 +00:00
2021-02-19 12:04:03 +00:00
``` bash
# Example with all arguments used
2019-05-16 11:17:15 +00:00
docker run \
--rm \
-it \
2019-06-03 11:32:42 +00:00
-u $(id -u $USER):$(id -g $USER) \
-v /<my_data_location>/input:/ocr_pipeline/input \
-v /<my_data_location>/output:/ocr_pipeline/output \
-v /<my_data_location>/logs:/ocr_pipeline/logs \
gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:development \
-i /ocr_pipeline/input \
2019-05-16 11:17:15 +00:00
-l eng \
-o /ocr_pipeline/output \
--binarize \
--log-dir /ocr_pipeline/logs \
--n-cores 8 \
2019-05-16 11:17:15 +00:00
```