2019-05-16 11:17:15 +00:00
# OCR
2019-04-02 13:43:41 +00:00
2019-05-16 11:17:15 +00:00
## Build image
2019-04-02 13:43:41 +00:00
2019-05-16 11:17:15 +00:00
1. Clone this repository and navigate into it:
```
git clone https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr.git & & cd ocr
```
2019-05-16 11:22:29 +00:00
2019-05-16 11:17:15 +00:00
2. Build image:
```
docker build -t sfb1288inf/ocr:latest .
```
2019-04-02 13:43:41 +00:00
2019-05-16 18:40:01 +00:00
Alternatively build from the GitLab repository without cloning:
2019-05-16 11:22:29 +00:00
2019-05-16 11:17:15 +00:00
1. Build image:
```
docker build -t sfb1288inf/ocr:latest https://gitlab.ub.uni-bielefeld.de/sfb1288inf/ocr.git
```
2019-04-02 13:43:41 +00:00
2019-05-16 11:17:15 +00:00
## Download prebuilt image
2019-04-02 13:43:41 +00:00
2019-05-16 11:17:15 +00:00
The GitLab registry provides a prebuilt image. It is automatically created, utilizing the conquaire build servers.
2019-04-02 13:43:41 +00:00
2019-05-16 11:17:15 +00:00
1. Download image:
```
docker pull gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:latest
```
2019-04-02 13:43:41 +00:00
2019-05-16 11:17:15 +00:00
## Run
2019-04-02 13:43:41 +00:00
2019-05-16 11:17:15 +00:00
1. Create input and output directories for the OCR software:
```
mkdir -p /< mydatalocation > /files_for_ocr /< mydatalocation > /files_from_ocr
```
2019-05-16 11:19:20 +00:00
2019-05-16 23:07:39 +00:00
2. Place your files inside the `/<mydatalocation>/files_for_ocr` directory. Files can either be PDF (.pdf) or multipage TIFF (.tiff, .tif) files. Files should all contain text of the same language.
2019-05-16 11:19:20 +00:00
2019-05-16 11:17:15 +00:00
3. Start the OCR process.
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) \
2019-06-02 19:38:30 +00:00
-v /< mydatalocation > /files_for_ocr:/input \
-v /< mydatalocation > /files_from_ocr:/output \
2019-05-16 11:17:15 +00:00
sfb1288inf/ocr:latest \
2019-06-02 19:38:30 +00:00
-i /input \
-l < languagecode > \
-o /output
2019-04-02 13:43:41 +00:00
```
2019-05-17 12:17:53 +00:00
The arguments below `sfb1288inf/ocr:latest` are described in the [OCR arguments ](#ocr-arguments ) part.
2019-05-16 11:19:20 +00:00
2019-05-20 10:06:57 +00:00
If you want to use the prebuilt image, replace `sfb1288inf/ocr:latest` with `gitlab.ub.uni-bielefeld.de:4567/sfb1288inf/ocr:latest` .
2019-05-16 11:17:15 +00:00
4. Check your results in the `/<mydatalocation>/files_from_ocr` directory.
### OCR arguments
`-l languagecode`
* Tells tesseract which language will be used.
2019-07-31 09:13:55 +00:00
* options = deu (German), eng (English), enm (Middle englisch), fra (French), frk (German Fraktur), frm (Middle french), ita (Italian), por (Portuguese), spa (Spanish)
2019-05-16 11:17:15 +00: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 11:26:19 +00:00
`--skip-binarisation`
2019-05-16 23:07:39 +00:00
* Used to skip binarization with ocropus. If skipped, only the tesseract binarization is used.
2019-05-16 11:17:15 +00:00
* default = False
2019-04-16 09:16:35 +00:00
2019-04-03 13:23:10 +00:00
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) \
2019-06-02 19:38:30 +00:00
-v "$HOME"/ocr/files_for_ocr:/input \
-v "$HOME"/ocr/files_from_ocr:/output \
2019-05-16 11:17:15 +00:00
sfb1288inf/ocr:latest \
2019-06-02 19:38:30 +00:00
-i /input \
2019-05-16 11:17:15 +00:00
-l eng \
2019-06-02 19:38:30 +00:00
-o /output \
2019-05-16 11:17:15 +00:00
--keep_intermediates \
--nCores 8 \
2019-05-16 11:26:19 +00:00
--skip-binarisation
2019-05-16 11:17:15 +00:00
```