Update config_params.json
commit
19116091f9
@ -0,0 +1,9 @@
|
|||||||
|
FROM python:3
|
||||||
|
|
||||||
|
ADD requirements.txt /
|
||||||
|
RUN pip install --proxy=http-proxy.sbb.spk-berlin.de:3128 -r requirements.txt
|
||||||
|
|
||||||
|
COPY . /usr/src/sbb_textline_detector
|
||||||
|
RUN pip install /usr/src/sbb_textline_detector
|
||||||
|
|
||||||
|
ENTRYPOINT ["sbb_textline_detector"]
|
@ -0,0 +1,37 @@
|
|||||||
|
# Textline-Recognition
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
# Installation:
|
||||||
|
|
||||||
|
Setup virtual environment:
|
||||||
|
```
|
||||||
|
virtualenv --python=python3.6 venv
|
||||||
|
```
|
||||||
|
|
||||||
|
Activate virtual environment:
|
||||||
|
```
|
||||||
|
source venv/bin/activate
|
||||||
|
```
|
||||||
|
|
||||||
|
Upgrade pip:
|
||||||
|
```
|
||||||
|
pip install -U pip
|
||||||
|
```
|
||||||
|
|
||||||
|
Install package together with its dependencies in development mode:
|
||||||
|
```
|
||||||
|
pip install -e ./
|
||||||
|
```
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
Perform document structure and textline analysis on a
|
||||||
|
scanned document image and save the result as PAGE XML.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
```
|
||||||
|
text_line_recognition --help
|
||||||
|
```
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
|||||||
|
qurator/sbb_textline_detector/ocrd-tool.json
|
@ -0,0 +1 @@
|
|||||||
|
__import__('pkg_resources').declare_namespace(__name__)
|
@ -0,0 +1,2 @@
|
|||||||
|
from .main import *
|
||||||
|
from .ocrd_cli import *
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"version": "0.0.1",
|
||||||
|
"tools": {
|
||||||
|
"ocrd_sbb_textline_detector": {
|
||||||
|
"executable": "ocrd_sbb_textline_detector",
|
||||||
|
"description": "Detect lines",
|
||||||
|
"steps": ["layout/segmentation/line"],
|
||||||
|
"input_file_grp": [
|
||||||
|
"OCR-D-IMG"
|
||||||
|
],
|
||||||
|
"output_file_grp": [
|
||||||
|
"OCR-D-SBB-SEG-LINE"
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"model": {"type": "string", "format": "file", "cacheable": true}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
import click
|
||||||
|
import ocrd_models.ocrd_page
|
||||||
|
from ocrd import Processor
|
||||||
|
from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor
|
||||||
|
from ocrd_modelfactory import page_from_file
|
||||||
|
from ocrd_models import OcrdFile
|
||||||
|
from ocrd_models.ocrd_page_generateds import MetadataItemType, LabelsType, LabelType
|
||||||
|
from ocrd_utils import concat_padded, getLogger, MIMETYPE_PAGE
|
||||||
|
from pkg_resources import resource_string
|
||||||
|
|
||||||
|
from qurator.sbb_textline_detector import textlineerkenner
|
||||||
|
|
||||||
|
log = getLogger('processor.OcrdSbbTextlineDetectorRecognize')
|
||||||
|
|
||||||
|
OCRD_TOOL = json.loads(resource_string(__name__, 'ocrd-tool.json').decode('utf8'))
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@ocrd_cli_options
|
||||||
|
def ocrd_sbb_textline_detector(*args, **kwargs):
|
||||||
|
return ocrd_cli_wrap_processor(OcrdSbbTextlineDetectorRecognize, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
TOOL = 'ocrd_sbb_textline_detector'
|
||||||
|
|
||||||
|
|
||||||
|
class OcrdSbbTextlineDetectorRecognize(Processor):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
kwargs['ocrd_tool'] = OCRD_TOOL['tools'][TOOL]
|
||||||
|
kwargs['version'] = OCRD_TOOL['version']
|
||||||
|
super(OcrdSbbTextlineDetectorRecognize, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def _make_file_id(self, input_file, input_file_grp, n):
|
||||||
|
file_id = input_file.ID.replace(input_file_grp, self.output_file_grp)
|
||||||
|
if file_id == input_file.ID:
|
||||||
|
file_id = concat_padded(self.output_file_grp, n)
|
||||||
|
return file_id
|
||||||
|
|
||||||
|
def _resolve_image_file(self, input_file: OcrdFile) -> str:
|
||||||
|
if input_file.mimetype == MIMETYPE_PAGE:
|
||||||
|
pcgts = page_from_file(self.workspace.download_file(input_file))
|
||||||
|
page = pcgts.get_Page()
|
||||||
|
image_file = page.imageFilename
|
||||||
|
else:
|
||||||
|
image_file = input_file.local_filename
|
||||||
|
return image_file
|
||||||
|
|
||||||
|
def process(self):
|
||||||
|
for n, page_id in enumerate(self.workspace.mets.physical_pages):
|
||||||
|
input_file = self.workspace.mets.find_files(fileGrp=self.input_file_grp, pageId=page_id)[0]
|
||||||
|
log.info("INPUT FILE %i / %s", n, input_file)
|
||||||
|
|
||||||
|
file_id = self._make_file_id(input_file, self.input_file_grp, n)
|
||||||
|
|
||||||
|
# Process the files
|
||||||
|
try:
|
||||||
|
os.mkdir(self.output_file_grp)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dirname:
|
||||||
|
# Segment the image
|
||||||
|
image_file = self._resolve_image_file(input_file)
|
||||||
|
model = self.parameter['model']
|
||||||
|
x = textlineerkenner(image_file, tmp_dirname, file_id, model)
|
||||||
|
x.run()
|
||||||
|
|
||||||
|
# Read segmentation results
|
||||||
|
tmp_filename = os.path.join(tmp_dirname, file_id) + '.xml'
|
||||||
|
tmp_pcgts = ocrd_models.ocrd_page.parse(tmp_filename)
|
||||||
|
tmp_page = tmp_pcgts.get_Page()
|
||||||
|
|
||||||
|
# Create a new PAGE file from the input file
|
||||||
|
pcgts = page_from_file(self.workspace.download_file(input_file))
|
||||||
|
page = pcgts.get_Page()
|
||||||
|
|
||||||
|
# Merge results → PAGE file
|
||||||
|
page.set_PrintSpace(tmp_page.get_PrintSpace())
|
||||||
|
page.set_ReadingOrder(tmp_page.get_ReadingOrder())
|
||||||
|
page.set_TextRegion(tmp_page.get_TextRegion())
|
||||||
|
|
||||||
|
# Save metadata about this operation
|
||||||
|
metadata = pcgts.get_Metadata()
|
||||||
|
metadata.add_MetadataItem(
|
||||||
|
MetadataItemType(type_="processingStep",
|
||||||
|
name=self.ocrd_tool['steps'][0],
|
||||||
|
value=TOOL,
|
||||||
|
Labels=[LabelsType(
|
||||||
|
externalModel="ocrd-tool",
|
||||||
|
externalId="parameters",
|
||||||
|
Label=[LabelType(type_=name, value=self.parameter[name])
|
||||||
|
for name in self.parameter.keys()])]))
|
||||||
|
|
||||||
|
self.workspace.add_file(
|
||||||
|
ID=file_id,
|
||||||
|
file_grp=self.output_file_grp,
|
||||||
|
pageId=page_id,
|
||||||
|
mimetype='application/vnd.prima.page+xml',
|
||||||
|
local_filename=os.path.join(self.output_file_grp, file_id) + '.xml',
|
||||||
|
content=ocrd_models.ocrd_page.to_xml(pcgts)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
ocrd_sbb_textline_detector()
|
@ -0,0 +1,12 @@
|
|||||||
|
opencv-python
|
||||||
|
numpy
|
||||||
|
matplotlib
|
||||||
|
seaborn
|
||||||
|
tqdm
|
||||||
|
keras
|
||||||
|
shapely
|
||||||
|
scikit-learn
|
||||||
|
tensorflow-gpu < 2.0
|
||||||
|
scipy
|
||||||
|
click
|
||||||
|
ocrd >= 2.0.0
|
@ -0,0 +1,38 @@
|
|||||||
|
from io import open
|
||||||
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
with open('requirements.txt') as fp:
|
||||||
|
install_requires = fp.read()
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name="qurator-sbb-textline",
|
||||||
|
version="0.0.1",
|
||||||
|
author="The Qurator Team",
|
||||||
|
author_email="qurator@sbb.spk-berlin.de",
|
||||||
|
description="Qurator",
|
||||||
|
long_description=open("README.md", "r", encoding='utf-8').read(),
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
keywords='qurator',
|
||||||
|
license='Apache',
|
||||||
|
url="https://qurator.ai",
|
||||||
|
packages=find_packages(exclude=["*.tests", "*.tests.*",
|
||||||
|
"tests.*", "tests"]),
|
||||||
|
install_requires=install_requires,
|
||||||
|
package_data={
|
||||||
|
'': ['*.json'],
|
||||||
|
},
|
||||||
|
entry_points={
|
||||||
|
'console_scripts': [
|
||||||
|
"sbb_textline_detector=qurator.sbb_textline_detector:main",
|
||||||
|
"ocrd_sbb_textline_detector=qurator.sbb_textline_detector:ocrd_sbb_textline_detector",
|
||||||
|
]
|
||||||
|
},
|
||||||
|
python_requires='>=3.6.0',
|
||||||
|
tests_require=['pytest'],
|
||||||
|
classifiers=[
|
||||||
|
'Intended Audience :: Science/Research',
|
||||||
|
'License :: OSI Approved :: Apache Software License',
|
||||||
|
'Programming Language :: Python :: 3',
|
||||||
|
'Topic :: Scientific/Engineering :: Artificial Intelligence',
|
||||||
|
],
|
||||||
|
)
|
Loading…
Reference in New Issue