mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-06-09 12:19:54 +02:00
Merge branch 'refs/heads/main' into extracting_images_only
# Conflicts: # src/eynollah/eynollah.py
This commit is contained in:
commit
de32d86fb6
35 changed files with 196 additions and 210 deletions
|
@ -1,51 +0,0 @@
|
||||||
version: 2
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
build-python37:
|
|
||||||
machine:
|
|
||||||
- image: ubuntu-2004:2023.02.1
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- restore_cache:
|
|
||||||
keys:
|
|
||||||
- model-cache
|
|
||||||
- run: make models
|
|
||||||
- save_cache:
|
|
||||||
key: model-cache
|
|
||||||
paths:
|
|
||||||
models_eynollah.tar.gz
|
|
||||||
models_eynollah
|
|
||||||
- run:
|
|
||||||
name: "Set Python Version"
|
|
||||||
command: pyenv install -s 3.7.16 && pyenv global 3.7.16
|
|
||||||
- run: make install
|
|
||||||
- run: make smoke-test
|
|
||||||
|
|
||||||
build-python38:
|
|
||||||
machine:
|
|
||||||
- image: ubuntu-2004:2023.02.1
|
|
||||||
steps:
|
|
||||||
- checkout
|
|
||||||
- restore_cache:
|
|
||||||
keys:
|
|
||||||
- model-cache
|
|
||||||
- run: make models
|
|
||||||
- save_cache:
|
|
||||||
key: model-cache
|
|
||||||
paths:
|
|
||||||
models_eynollah.tar.gz
|
|
||||||
models_eynollah
|
|
||||||
- run:
|
|
||||||
name: "Set Python Version"
|
|
||||||
command: pyenv install -s 3.8.16 && pyenv global 3.8.16
|
|
||||||
- run: make install
|
|
||||||
- run: make smoke-test
|
|
||||||
|
|
||||||
workflows:
|
|
||||||
version: 2
|
|
||||||
build:
|
|
||||||
jobs:
|
|
||||||
# - build-python37
|
|
||||||
- build-python38
|
|
8
.github/workflows/test-eynollah.yml
vendored
8
.github/workflows/test-eynollah.yml
vendored
|
@ -1,7 +1,7 @@
|
||||||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
|
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
||||||
|
|
||||||
name: Python package
|
name: Test
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ jobs:
|
||||||
python-version: ['3.8', '3.9', '3.10', '3.11']
|
python-version: ['3.8', '3.9', '3.10', '3.11']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/cache@v2
|
- uses: actions/cache@v4
|
||||||
id: model_cache
|
id: model_cache
|
||||||
with:
|
with:
|
||||||
path: models_eynollah
|
path: models_eynollah
|
||||||
|
@ -24,7 +24,7 @@ jobs:
|
||||||
if: steps.model_cache.outputs.cache-hit != 'true'
|
if: steps.model_cache.outputs.cache-hit != 'true'
|
||||||
run: make models
|
run: make models
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -5,6 +5,14 @@ Versioned according to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## [0.3.1] - 2024-08-27
|
||||||
|
|
||||||
|
Fixed:
|
||||||
|
|
||||||
|
* regression in OCR-D processor, #106
|
||||||
|
* Expected Ptrcv::UMat for argument 'contour', #110
|
||||||
|
* Memory usage explosion with very narrow images (e.g. book spine), #67
|
||||||
|
|
||||||
## [0.3.0] - 2023-05-13
|
## [0.3.0] - 2023-05-13
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
|
@ -117,6 +125,8 @@ Fixed:
|
||||||
Initial release
|
Initial release
|
||||||
|
|
||||||
<!-- link-labels -->
|
<!-- link-labels -->
|
||||||
|
[0.3.1]: ../../compare/v0.3.1...v0.3.0
|
||||||
|
[0.3.0]: ../../compare/v0.3.0...v0.2.0
|
||||||
[0.2.0]: ../../compare/v0.2.0...v0.1.0
|
[0.2.0]: ../../compare/v0.2.0...v0.1.0
|
||||||
[0.1.0]: ../../compare/v0.1.0...v0.0.11
|
[0.1.0]: ../../compare/v0.1.0...v0.0.11
|
||||||
[0.0.11]: ../../compare/v0.0.11...v0.0.10
|
[0.0.11]: ../../compare/v0.0.11...v0.0.10
|
||||||
|
|
7
Makefile
7
Makefile
|
@ -24,12 +24,15 @@ models: models_eynollah
|
||||||
models_eynollah: models_eynollah.tar.gz
|
models_eynollah: models_eynollah.tar.gz
|
||||||
# tar xf models_eynollah_renamed.tar.gz --transform 's/models_eynollah_renamed/models_eynollah/'
|
# tar xf models_eynollah_renamed.tar.gz --transform 's/models_eynollah_renamed/models_eynollah/'
|
||||||
# tar xf models_eynollah_renamed.tar.gz
|
# tar xf models_eynollah_renamed.tar.gz
|
||||||
tar xf 2022-04-05.SavedModel.tar.gz --transform 's/models_eynollah_renamed/models_eynollah/'
|
# tar xf models_eynollah_renamed_savedmodel.tar.gz --transform 's/models_eynollah_renamed_savedmodel/models_eynollah/'
|
||||||
|
tar xf models_eynollah.tar.gz
|
||||||
|
|
||||||
models_eynollah.tar.gz:
|
models_eynollah.tar.gz:
|
||||||
# wget 'https://qurator-data.de/eynollah/2021-04-25/models_eynollah.tar.gz'
|
# wget 'https://qurator-data.de/eynollah/2021-04-25/models_eynollah.tar.gz'
|
||||||
# wget 'https://qurator-data.de/eynollah/2022-04-05/models_eynollah_renamed.tar.gz'
|
# wget 'https://qurator-data.de/eynollah/2022-04-05/models_eynollah_renamed.tar.gz'
|
||||||
wget 'https://ocr-d.kba.cloud/2022-04-05.SavedModel.tar.gz'
|
# wget 'https://ocr-d.kba.cloud/2022-04-05.SavedModel.tar.gz'
|
||||||
|
# wget 'https://qurator-data.de/eynollah/2022-04-05/models_eynollah_renamed_savedmodel.tar.gz'
|
||||||
|
wget https://github.com/qurator-spk/eynollah/releases/download/v0.3.0/models_eynollah.tar.gz
|
||||||
|
|
||||||
# Install with pip
|
# Install with pip
|
||||||
install:
|
install:
|
||||||
|
|
67
README.md
67
README.md
|
@ -1,10 +1,10 @@
|
||||||
# Eynollah
|
# Eynollah
|
||||||
> Document Layout Analysis (segmentation) using pre-trained models and heuristics
|
> Document Layout Analysis with Deep Learning and Heuristics
|
||||||
|
|
||||||
[](https://pypi.org/project/eynollah/)
|
[](https://pypi.org/project/eynollah/)
|
||||||
[](https://circleci.com/gh/qurator-spk/eynollah)
|
|
||||||
[](https://github.com/qurator-spk/eynollah/actions/workflows/test-eynollah.yml)
|
[](https://github.com/qurator-spk/eynollah/actions/workflows/test-eynollah.yml)
|
||||||
[](https://opensource.org/license/apache-2-0/)
|
[](https://opensource.org/license/apache-2-0/)
|
||||||
|
[](https://doi.org/10.1145/3604951.3605513)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -14,17 +14,18 @@
|
||||||
* Support for various image optimization operations:
|
* Support for various image optimization operations:
|
||||||
* cropping (border detection), binarization, deskewing, dewarping, scaling, enhancing, resizing
|
* cropping (border detection), binarization, deskewing, dewarping, scaling, enhancing, resizing
|
||||||
* Text line segmentation to bounding boxes or polygons (contours) including for curved lines and vertical text
|
* Text line segmentation to bounding boxes or polygons (contours) including for curved lines and vertical text
|
||||||
* Detection of reading order
|
* Detection of reading order (left-to-right or right-to-left)
|
||||||
* Output in [PAGE-XML](https://github.com/PRImA-Research-Lab/PAGE-XML)
|
* Output in [PAGE-XML](https://github.com/PRImA-Research-Lab/PAGE-XML)
|
||||||
* [OCR-D](https://github.com/qurator-spk/eynollah#use-as-ocr-d-processor) interface
|
* [OCR-D](https://github.com/qurator-spk/eynollah#use-as-ocr-d-processor) interface
|
||||||
|
|
||||||
|
:warning: Development is currently focused on achieving the best possible quality of results for a wide variety of historical documents and therefore processing can be very slow. We aim to improve this, but contributions are welcome.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Python versions `3.8-3.11` with Tensorflow versions >=`2.12` on Linux are currently supported. Unfortunately we can not currently support Windows or MacOS.
|
Python `3.8-3.11` with Tensorflow `2.12-2.15` on Linux are currently supported.
|
||||||
Windows users may be able to successfully run the tool through [WSL](https://learn.microsoft.com/en-us/windows/wsl/).
|
|
||||||
|
|
||||||
For (limited) GPU support the CUDA toolkit needs to be installed.
|
For (limited) GPU support the CUDA toolkit needs to be installed.
|
||||||
|
|
||||||
You can either install via
|
You can either install from PyPI
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install eynollah
|
pip install eynollah
|
||||||
|
@ -40,45 +41,48 @@ cd eynollah; pip install -e .
|
||||||
Alternatively, you can run `make install` or `make install-dev` for editable installation.
|
Alternatively, you can run `make install` or `make install-dev` for editable installation.
|
||||||
|
|
||||||
## Models
|
## Models
|
||||||
Pre-trained models can be downloaded from [qurator-data.de](https://qurator-data.de/eynollah/).
|
Pre-trained models can be downloaded from [qurator-data.de](https://qurator-data.de/eynollah/) or [huggingface](https://huggingface.co/SBB?search_models=eynollah).
|
||||||
|
|
||||||
In case you want to train your own model to use with Eynollah, have a look at [sbb_pixelwise_segmentation](https://github.com/qurator-spk/sbb_pixelwise_segmentation).
|
## Train
|
||||||
|
🚧 **Work in progress**
|
||||||
|
|
||||||
|
In case you want to train your own model, have a look at [`sbb_pixelwise_segmentation`](https://github.com/qurator-spk/sbb_pixelwise_segmentation).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
The command-line interface can be called like this:
|
The command-line interface can be called like this:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
eynollah \
|
eynollah \
|
||||||
-i <image file> \
|
-i <single image file> | -di <directory containing image files> \
|
||||||
-o <output directory> \
|
-o <output directory> \
|
||||||
-m <path to directory containing model files> \
|
-m <directory containing model files> \
|
||||||
[OPTIONS]
|
[OPTIONS]
|
||||||
```
|
```
|
||||||
|
|
||||||
The following options can be used to further configure the processing:
|
The following options can be used to further configure the processing:
|
||||||
|
|
||||||
| option | description |
|
| option | description |
|
||||||
|----------|:-------------|
|
|-------------------|:-------------------------------------------------------------------------------|
|
||||||
| `-fl` | full layout analysis including all steps and segmentation classes |
|
| `-fl` | full layout analysis including all steps and segmentation classes |
|
||||||
| `-light` | lighter and faster but simpler method for main region detection and deskewing |
|
| `-light` | lighter and faster but simpler method for main region detection and deskewing |
|
||||||
| `-tab` | apply table detection |
|
| `-tab` | apply table detection |
|
||||||
| `-ae` | apply enhancement (the resulting image is saved to the output directory) |
|
| `-ae` | apply enhancement (the resulting image is saved to the output directory) |
|
||||||
| `-as` | apply scaling |
|
| `-as` | apply scaling |
|
||||||
| `-cl` | apply contour detection for curved text lines instead of bounding boxes |
|
| `-cl` | apply contour detection for curved text lines instead of bounding boxes |
|
||||||
| `-ib` | apply binarization (the resulting image is saved to the output directory) |
|
| `-ib` | apply binarization (the resulting image is saved to the output directory) |
|
||||||
| `-ep` | enable plotting (MUST always be used with `-sl`, `-sd`, `-sa`, `-si` or `-ae`) |
|
| `-ep` | enable plotting (MUST always be used with `-sl`, `-sd`, `-sa`, `-si` or `-ae`) |
|
||||||
| `-ho` | ignore headers for reading order dectection |
|
| `-ho` | ignore headers for reading order dectection |
|
||||||
| `-di <directory>` | process all images in a directory in batch mode |
|
| `-si <directory>` | save image regions detected to this directory |
|
||||||
| `-si <directory>` | save image regions detected to this directory |
|
| `-sd <directory>` | save deskewed image to this directory |
|
||||||
| `-sd <directory>` | save deskewed image to this directory |
|
| `-sl <directory>` | save layout prediction as plot to this directory |
|
||||||
| `-sl <directory>` | save layout prediction as plot to this directory |
|
| `-sp <directory>` | save cropped page image to this directory |
|
||||||
| `-sp <directory>` | save cropped page image to this directory |
|
| `-sa <directory>` | save all (plot, enhanced/binary image, layout) to this directory |
|
||||||
| `-sa <directory>` | save all (plot, enhanced/binary image, layout) to this directory |
|
|
||||||
|
|
||||||
If no option is set, the tool will perform layout detection of main regions (background, text, images, separators and marginals).
|
If no option is set, the tool performs layout detection of main regions (background, text, images, separators and marginals).
|
||||||
The tool produces better quality output when RGB images are used as input than greyscale or binarized images.
|
The best output quality is produced when RGB images are used as input rather than greyscale or binarized images.
|
||||||
|
|
||||||
#### Use as OCR-D processor
|
#### Use as OCR-D processor
|
||||||
|
🚧 **Work in progress**
|
||||||
|
|
||||||
Eynollah ships with a CLI interface to be used as [OCR-D](https://ocr-d.de) processor.
|
Eynollah ships with a CLI interface to be used as [OCR-D](https://ocr-d.de) processor.
|
||||||
|
|
||||||
|
@ -96,11 +100,14 @@ ocrd-eynollah-segment -I OCR-D-IMG-BIN -O SEG-LINE -P models
|
||||||
|
|
||||||
uses the original (RGB) image despite any binarization that may have occured in previous OCR-D processing steps
|
uses the original (RGB) image despite any binarization that may have occured in previous OCR-D processing steps
|
||||||
|
|
||||||
|
#### Additional documentation
|
||||||
|
Please check the [wiki](https://github.com/qurator-spk/eynollah/wiki).
|
||||||
|
|
||||||
## How to cite
|
## How to cite
|
||||||
If you find this tool useful in your work, please consider citing our paper:
|
If you find this tool useful in your work, please consider citing our paper:
|
||||||
|
|
||||||
```bibtex
|
```bibtex
|
||||||
@inproceedings{rezanezhad2023eynollah,
|
@inproceedings{hip23rezanezhad,
|
||||||
title = {Document Layout Analysis with Deep Learning and Heuristics},
|
title = {Document Layout Analysis with Deep Learning and Heuristics},
|
||||||
author = {Rezanezhad, Vahid and Baierer, Konstantin and Gerber, Mike and Labusch, Kai and Neudecker, Clemens},
|
author = {Rezanezhad, Vahid and Baierer, Konstantin and Gerber, Mike and Labusch, Kai and Neudecker, Clemens},
|
||||||
booktitle = {Proceedings of the 7th International Workshop on Historical Document Imaging and Processing {HIP} 2023,
|
booktitle = {Proceedings of the 7th International Workshop on Historical Document Imaging and Processing {HIP} 2023,
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
qurator/eynollah/ocrd-tool.json
|
src/eynollah/ocrd-tool.json
|
43
pyproject.toml
Normal file
43
pyproject.toml
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=61.0", "wheel", "setuptools-ocrd"]
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "eynollah"
|
||||||
|
authors = [
|
||||||
|
{name = "Vahid Rezanezhad"},
|
||||||
|
{name = "Staatsbibliothek zu Berlin - Preußischer Kulturbesitz"},
|
||||||
|
]
|
||||||
|
description = "Document Layout Analysis"
|
||||||
|
readme = "README.md"
|
||||||
|
license.file = "LICENSE"
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
keywords = ["document layout analysis", "image segmentation"]
|
||||||
|
|
||||||
|
dynamic = ["dependencies", "version"]
|
||||||
|
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 4 - Beta",
|
||||||
|
"Environment :: Console",
|
||||||
|
"Intended Audience :: Science/Research",
|
||||||
|
"License :: OSI Approved :: Apache Software License",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
|
"Topic :: Scientific/Engineering :: Image Processing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
eynollah = "eynollah.cli:main"
|
||||||
|
ocrd-eynollah-segment = "eynollah.ocrd_cli:main"
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Homepage = "https://github.com/qurator-spk/eynollah"
|
||||||
|
Repository = "https://github.com/qurator-spk/eynollah.git"
|
||||||
|
|
||||||
|
[tool.setuptools.dynamic]
|
||||||
|
dependencies = {file = ["requirements.txt"]}
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
where = ["src"]
|
||||||
|
|
||||||
|
[tool.setuptools.package-data]
|
||||||
|
"*" = ["*.json", '*.yml', '*.xml', '*.xsd']
|
|
@ -1 +0,0 @@
|
||||||
__import__("pkg_resources").declare_namespace(__name__)
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
ocrd >= 2.23.3
|
ocrd >= 2.23.3
|
||||||
numpy <1.24.0
|
numpy <1.24.0
|
||||||
scikit-learn >= 0.23.2
|
scikit-learn >= 0.23.2
|
||||||
tensorflow >=2.12.0
|
tensorflow == 2.12.1
|
||||||
imutils >= 0.5.3
|
imutils >= 0.5.3
|
||||||
matplotlib
|
matplotlib
|
||||||
setuptools >= 50
|
setuptools >= 50
|
||||||
|
|
28
setup.py
28
setup.py
|
@ -1,28 +0,0 @@
|
||||||
from setuptools import setup, find_packages
|
|
||||||
from json import load
|
|
||||||
|
|
||||||
install_requires = open('requirements.txt').read().split('\n')
|
|
||||||
with open('ocrd-tool.json', 'r', encoding='utf-8') as f:
|
|
||||||
version = load(f)['version']
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name='eynollah',
|
|
||||||
version=version,
|
|
||||||
long_description=open('README.md').read(),
|
|
||||||
long_description_content_type='text/markdown',
|
|
||||||
author='Vahid Rezanezhad',
|
|
||||||
url='https://github.com/qurator-spk/eynollah',
|
|
||||||
license='Apache License 2.0',
|
|
||||||
namespace_packages=['qurator'],
|
|
||||||
packages=find_packages(exclude=['tests']),
|
|
||||||
install_requires=install_requires,
|
|
||||||
package_data={
|
|
||||||
'': ['*.json']
|
|
||||||
},
|
|
||||||
entry_points={
|
|
||||||
'console_scripts': [
|
|
||||||
'eynollah=qurator.eynollah.cli:main',
|
|
||||||
'ocrd-eynollah-segment=qurator.eynollah.ocrd_cli:main',
|
|
||||||
]
|
|
||||||
},
|
|
||||||
)
|
|
|
@ -1,7 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import click
|
import click
|
||||||
from ocrd_utils import initLogging, setOverrideLogLevel
|
from ocrd_utils import initLogging, setOverrideLogLevel
|
||||||
from qurator.eynollah.eynollah import Eynollah
|
from eynollah.eynollah import Eynollah
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
@ -209,9 +209,11 @@ def main(
|
||||||
light_version=light_version,
|
light_version=light_version,
|
||||||
ignore_page_extraction=ignore_page_extraction,
|
ignore_page_extraction=ignore_page_extraction,
|
||||||
)
|
)
|
||||||
eynollah.run()
|
if dir_in:
|
||||||
#pcgts = eynollah.run()
|
eynollah.run()
|
||||||
##eynollah.writer.write_pagexml(pcgts)
|
else:
|
||||||
|
pcgts = eynollah.run()
|
||||||
|
eynollah.writer.write_pagexml(pcgts)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -29,7 +29,8 @@ warnings.filterwarnings("ignore")
|
||||||
from scipy.signal import find_peaks
|
from scipy.signal import find_peaks
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from scipy.ndimage import gaussian_filter1d
|
from scipy.ndimage import gaussian_filter1d
|
||||||
from tensorflow.python.keras.backend import set_session
|
# use tf1 compatibility for keras backend
|
||||||
|
from tensorflow.compat.v1.keras.backend import set_session
|
||||||
from tensorflow.keras import layers
|
from tensorflow.keras import layers
|
||||||
|
|
||||||
from .utils.contour import (
|
from .utils.contour import (
|
||||||
|
@ -287,7 +288,6 @@ class Eynollah:
|
||||||
self.ls_imgs = os.listdir(self.dir_in)
|
self.ls_imgs = os.listdir(self.dir_in)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _cache_images(self, image_filename=None, image_pil=None):
|
def _cache_images(self, image_filename=None, image_pil=None):
|
||||||
ret = {}
|
ret = {}
|
||||||
if image_filename:
|
if image_filename:
|
||||||
|
@ -624,9 +624,6 @@ class Eynollah:
|
||||||
image_res = np.copy(img)
|
image_res = np.copy(img)
|
||||||
is_image_enhanced = False
|
is_image_enhanced = False
|
||||||
else:
|
else:
|
||||||
#img_new, num_column_is_classified = self.calculate_width_height_by_columns_extract_only_images(img, num_col, width_early, label_p_pred)
|
|
||||||
#image_res = np.copy(img_new)
|
|
||||||
#is_image_enhanced = True
|
|
||||||
num_column_is_classified = True
|
num_column_is_classified = True
|
||||||
image_res = np.copy(img)
|
image_res = np.copy(img)
|
||||||
is_image_enhanced = False
|
is_image_enhanced = False
|
||||||
|
@ -925,6 +922,7 @@ class Eynollah:
|
||||||
seg_not_base[seg_not_base<1] =0
|
seg_not_base[seg_not_base<1] =0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
seg_test = label_p_pred[0,:,:,1]
|
seg_test = label_p_pred[0,:,:,1]
|
||||||
##seg2 = -label_p_pred[0,:,:,2]
|
##seg2 = -label_p_pred[0,:,:,2]
|
||||||
|
|
||||||
|
@ -3273,19 +3271,23 @@ class Eynollah:
|
||||||
else:
|
else:
|
||||||
order_text_new, id_of_texts_tot = self.do_order_of_regions(contours_only_text_parent_d_ordered, contours_only_text_parent_h_d_ordered, boxes_d, textline_mask_tot_d)
|
order_text_new, id_of_texts_tot = self.do_order_of_regions(contours_only_text_parent_d_ordered, contours_only_text_parent_h_d_ordered, boxes_d, textline_mask_tot_d)
|
||||||
|
|
||||||
pcgts = self.writer.build_pagexml_full_layout(contours_only_text_parent, contours_only_text_parent_h, page_coord, order_text_new, id_of_texts_tot, all_found_textline_polygons, all_found_textline_polygons_h, all_box_coord, all_box_coord_h, polygons_of_images, contours_tables, polygons_of_drop_capitals, polygons_of_marginals, all_found_textline_polygons_marginals, all_box_coord_marginals, slopes, slopes_h, slopes_marginals, cont_page, polygons_lines_xml)
|
pcgts = self.writer.build_pagexml_full_layout(contours_only_text_parent, contours_only_text_parent_h, page_coord, order_text_new, id_of_texts_tot, all_found_textline_polygons, all_found_textline_polygons_h, all_box_coord, all_box_coord_h, polygons_of_images, contours_tables, polygons_of_drop_capitals, polygons_of_marginals, all_found_textline_polygons_marginals, all_box_coord_marginals, slopes, slopes_h, slopes_marginals, cont_page, polygons_lines_xml)
|
||||||
self.logger.info("Job done in %.1fs", time.time() - t0)
|
self.logger.info("Job done in %.1fs", time.time() - t0)
|
||||||
##return pcgts
|
if not self.dir_in:
|
||||||
|
return pcgts
|
||||||
|
else:
|
||||||
|
contours_only_text_parent_h = None
|
||||||
|
if np.abs(slope_deskew) < SLOPE_THRESHOLD:
|
||||||
|
order_text_new, id_of_texts_tot = self.do_order_of_regions(contours_only_text_parent, contours_only_text_parent_h, boxes, textline_mask_tot)
|
||||||
else:
|
else:
|
||||||
contours_only_text_parent_h = None
|
contours_only_text_parent_d_ordered = list(np.array(contours_only_text_parent_d_ordered, dtype=object)[index_by_text_par_con])
|
||||||
if np.abs(slope_deskew) < SLOPE_THRESHOLD:
|
order_text_new, id_of_texts_tot = self.do_order_of_regions(contours_only_text_parent_d_ordered, contours_only_text_parent_h, boxes_d, textline_mask_tot_d)
|
||||||
order_text_new, id_of_texts_tot = self.do_order_of_regions(contours_only_text_parent, contours_only_text_parent_h, boxes, textline_mask_tot)
|
pcgts = self.writer.build_pagexml_no_full_layout(txt_con_org, page_coord, order_text_new, id_of_texts_tot, all_found_textline_polygons, all_box_coord, polygons_of_images, polygons_of_marginals, all_found_textline_polygons_marginals, all_box_coord_marginals, slopes, slopes_marginals, cont_page, polygons_lines_xml, contours_tables)
|
||||||
else:
|
self.logger.info("Job done in %.1fs", time.time() - t0)
|
||||||
contours_only_text_parent_d_ordered = list(np.array(contours_only_text_parent_d_ordered, dtype=object)[index_by_text_par_con])
|
if not self.dir_in:
|
||||||
order_text_new, id_of_texts_tot = self.do_order_of_regions(contours_only_text_parent_d_ordered, contours_only_text_parent_h, boxes_d, textline_mask_tot_d)
|
return pcgts
|
||||||
pcgts = self.writer.build_pagexml_no_full_layout(txt_con_org, page_coord, order_text_new, id_of_texts_tot, all_found_textline_polygons, all_box_coord, polygons_of_images, polygons_of_marginals, all_found_textline_polygons_marginals, all_box_coord_marginals, slopes, slopes_marginals, cont_page, polygons_lines_xml, contours_tables)
|
|
||||||
self.logger.info("Job done in %.1fs", time.time() - t0)
|
if self.dir_in:
|
||||||
##return pcgts
|
|
||||||
self.writer.write_pagexml(pcgts)
|
self.writer.write_pagexml(pcgts)
|
||||||
#self.logger.info("Job done in %.1fs", time.time() - t0)
|
#self.logger.info("Job done in %.1fs", time.time() - t0)
|
||||||
if self.dir_in:
|
if self.dir_in:
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"git_url": "https://github.com/qurator-spk/eynollah",
|
"git_url": "https://github.com/qurator-spk/eynollah",
|
||||||
"tools": {
|
"tools": {
|
||||||
"ocrd-eynollah-segment": {
|
"ocrd-eynollah-segment": {
|
|
@ -42,7 +42,7 @@ class EynollahProcessor(Processor):
|
||||||
page = pcgts.get_Page()
|
page = pcgts.get_Page()
|
||||||
# XXX loses DPI information
|
# XXX loses DPI information
|
||||||
# page_image, _, _ = self.workspace.image_from_page(page, page_id, feature_filter='binarized')
|
# page_image, _, _ = self.workspace.image_from_page(page, page_id, feature_filter='binarized')
|
||||||
image_filename = self.workspace.download_file(next(self.workspace.mets.find_files(url=page.imageFilename))).local_filename
|
image_filename = self.workspace.download_file(next(self.workspace.mets.find_files(local_filename=page.imageFilename))).local_filename
|
||||||
eynollah_kwargs = {
|
eynollah_kwargs = {
|
||||||
'dir_models': self.resolve_resource(self.parameter['models']),
|
'dir_models': self.resolve_resource(self.parameter['models']),
|
||||||
'allow_enhancement': False,
|
'allow_enhancement': False,
|
|
@ -1,5 +1,5 @@
|
||||||
from tests.base import main
|
from tests.base import main
|
||||||
from qurator.eynollah.utils.counter import EynollahIdCounter
|
from eynollah.utils.counter import EynollahIdCounter
|
||||||
|
|
||||||
def test_counter_string():
|
def test_counter_string():
|
||||||
c = EynollahIdCounter()
|
c = EynollahIdCounter()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import cv2
|
import cv2
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from qurator.eynollah.utils.pil_cv2 import check_dpi
|
from eynollah.utils.pil_cv2 import check_dpi
|
||||||
from tests.base import main
|
from tests.base import main
|
||||||
|
|
||||||
def test_dpi():
|
def test_dpi():
|
||||||
|
|
|
@ -2,7 +2,7 @@ from os import environ
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from ocrd_utils import pushd_popd
|
from ocrd_utils import pushd_popd
|
||||||
from tests.base import CapturingTestCase as TestCase, main
|
from tests.base import CapturingTestCase as TestCase, main
|
||||||
from qurator.eynollah.cli import main as eynollah_cli
|
from eynollah.cli import main as eynollah_cli
|
||||||
|
|
||||||
testdir = Path(__file__).parent.resolve()
|
testdir = Path(__file__).parent.resolve()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
def test_utils_import():
|
def test_utils_import():
|
||||||
import qurator.eynollah.utils
|
import eynollah.utils
|
||||||
import qurator.eynollah.utils.contour
|
import eynollah.utils.contour
|
||||||
import qurator.eynollah.utils.drop_capitals
|
import eynollah.utils.drop_capitals
|
||||||
import qurator.eynollah.utils.drop_capitals
|
import eynollah.utils.drop_capitals
|
||||||
import qurator.eynollah.utils.is_nan
|
import eynollah.utils.is_nan
|
||||||
import qurator.eynollah.utils.rotate
|
import eynollah.utils.rotate
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from pytest import main
|
from pytest import main
|
||||||
from qurator.eynollah.utils.xml import create_page_xml
|
from eynollah.utils.xml import create_page_xml
|
||||||
from ocrd_models.ocrd_page import to_xml
|
from ocrd_models.ocrd_page import to_xml
|
||||||
|
|
||||||
PAGE_2019 = 'http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15'
|
PAGE_2019 = 'http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue