Skip to content

Commit

Permalink
Merge branch 'port-to-v3' of https://github.com/OCR-D/ocrd_kraken int…
Browse files Browse the repository at this point in the history
…o port-to-v3

# Conflicts:
#	ocrd_kraken/binarize.py
  • Loading branch information
kba committed Aug 14, 2024
2 parents c0c1eb7 + a497287 commit 712d1d3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 41 deletions.
2 changes: 0 additions & 2 deletions ocrd_kraken/binarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def executable(self):

def setup(self):
self.logger = getLogger('processor.KrakenBinarize')
assert_file_grp_cardinality(self.input_file_grp, 1)
assert_file_grp_cardinality(self.output_file_grp, 1)

def process_page_pcgts(self, *input_pcgts: OcrdPage, output_file_id: Optional[str] = None, page_id: Optional[str] = None) -> OcrdProcessResult:
"""Binarize the pages/regions/lines with Kraken.
Expand Down
12 changes: 6 additions & 6 deletions ocrd_kraken/ocrd-tool.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"tools": {
"ocrd-kraken-binarize": {
"executable": "ocrd-kraken-binarize",
"input_file_grp": ["OCR-D-IMG", "OCR-D-PRE-CROP", "OCR-D-SEG-REGION", "OCR-D-SEG-LINE"],
"output_file_grp": ["OCR-D-PRE-BIN"],
"input_file_grp_cardinality": 1,
"output_file_grp_cardinality": 1,
"categories": [
"Image preprocessing"
],
Expand All @@ -24,8 +24,8 @@
},
"ocrd-kraken-segment": {
"executable": "ocrd-kraken-segment",
"input_file_grp": ["OCR-D-IMG", "OCR-D-PRE-CROP", "OCR-D-PRE-BIN"],
"output_file_grp": ["OCR-D-SEG-REGION", "OCR-D-SEG-LINE"],
"input_file_grp_cardinality": 1,
"output_file_grp_cardinality": 1,
"categories": [
"Layout analysis"
],
Expand Down Expand Up @@ -128,8 +128,8 @@
},
"ocrd-kraken-recognize": {
"executable": "ocrd-kraken-recognize",
"input_file_grp": ["OCR-D-SEG-LINE"],
"output_file_grp": ["OCR-D-OCR-KRAK"],
"input_file_grp_cardinality": 1,
"output_file_grp_cardinality": 1,
"categories": ["Text recognition and optimization"],
"steps": ["recognition/text-recognition"],
"description": "Text recognition with Kraken",
Expand Down
4 changes: 1 addition & 3 deletions ocrd_kraken/recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ def executable(self):

def setup(self):
"""
Assert filegrp cardinality, load model, set predict function
Load model, set predict function
"""
assert_file_grp_cardinality(self.input_file_grp, 1)
assert_file_grp_cardinality(self.output_file_grp, 1)

self.logger = getLogger('processor.KrakenRecognize')
import torch
Expand Down
2 changes: 0 additions & 2 deletions ocrd_kraken/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def setup(self):
Load models
"""
self.logger = getLogger('processor.KrakenSegment')
assert_file_grp_cardinality(self.input_file_grp, 1)
assert_file_grp_cardinality(self.output_file_grp, 1)
kwargs = {}
kwargs['text_direction'] = self.parameter['text_direction']
self.use_legacy = self.parameter['use_legacy']
Expand Down
26 changes: 13 additions & 13 deletions tests/test_binarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from tests.base import assets, main

from ocrd import Resolver
from ocrd import Resolver, run_processor
from ocrd_kraken.binarize import KrakenBinarize
from ocrd_utils.logging import setOverrideLogLevel

Expand Down Expand Up @@ -37,24 +37,24 @@ def workspace(tmpdir):
# )

def test_binarize_regions(workspace):
proc = KrakenBinarize(
workspace,
input_file_grp="OCR-D-GT-PAGE",
output_file_grp="OCR-D-IMG-BIN-KRAKEN",
parameter={'level-of-operation': 'region'}
run_processor(KrakenBinarize,
workspace=workspace,
input_file_grp="OCR-D-GT-PAGE",
output_file_grp="OCR-D-IMG-BIN-KRAKEN",
parameter={'level-of-operation': 'region'}
)
proc.process()
workspace.save_mets()
# FIXME: add result assertions (find_files, parsing PAGE etc)

def test_binarize_lines(workspace):
proc = KrakenBinarize(
workspace,
input_file_grp="OCR-D-GT-PAGE",
output_file_grp="OCR-D-IMG-BIN-KRAKEN",
parameter={'level-of-operation': 'line'}
run_processor(KrakenBinarize,
workspace=workspace,
input_file_grp="OCR-D-GT-PAGE",
output_file_grp="OCR-D-IMG-BIN-KRAKEN",
parameter={'level-of-operation': 'line'}
)
proc.process()
workspace.save_mets()
# FIXME: add result assertions (find_files, parsing PAGE etc)

if __name__ == "__main__":
main(__file__)
10 changes: 5 additions & 5 deletions tests/test_recognize.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def test_recognize(self):
with pushd_popd(tempdir=True) as tempdir:
workspace = resolver.workspace_from_url(assets.path_to('communist_manifesto/data/mets.xml'), dst_dir=tempdir, download=True)
workspace.overwrite_mode = True
proc = KrakenRecognize(
workspace,
input_file_grp="OCR-D-SEG-KRAKEN",
output_file_grp="OCR-D-OCR-KRAKEN",
run_processor(KrakenRecognize,
workspace=workspace,
input_file_grp="OCR-D-SEG-KRAKEN",
output_file_grp="OCR-D-OCR-KRAKEN",
)
proc.process()
workspace.save_mets()
# FIXME: add result assertions (find_files, parsing PAGE etc)

if __name__ == "__main__":
main(__file__)
23 changes: 13 additions & 10 deletions tests/test_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from tests.base import TestCase, assets, main

from ocrd import Resolver
from ocrd import Resolver, run_processor
from ocrd_utils import initLogging, pushd_popd
from ocrd_kraken.segment import KrakenSegment

Expand All @@ -18,42 +18,45 @@ def test_run_blla(self):
resolver = Resolver()
with pushd_popd(tempdir=True) as tempdir:
workspace = resolver.workspace_from_url(assets.path_to('communist_manifesto/data/mets.xml'), dst_dir=tempdir, download=True)
proc = KrakenSegment(
workspace,
run_processor(
KrakenSegment,
workspace=workspace,
input_file_grp="OCR-D-IMG-BIN",
output_file_grp="OCR-D-SEG-LINE-KRAKEN",
parameter={'maxcolseps': 0, 'use_legacy': False}
)
proc.process()
workspace.save_mets()
# FIXME: add result assertions (find_files, parsing PAGE etc)

def test_run_blla_regionlevel(self):
resolver = Resolver()
with pushd_popd(tempdir=True) as tempdir:
workspace = resolver.workspace_from_url(assets.path_to('kant_aufklaerung_1784-page-region/data/mets.xml'), dst_dir=tempdir, download=True)
proc = KrakenSegment(
workspace,
run_processor(
KrakenSegment,
workspace=workspace,
input_file_grp="OCR-D-GT-SEG-REGION",
output_file_grp="OCR-D-SEG-LINE-KRAKEN",
page_id="phys_0005",
parameter={'maxcolseps': 0, 'use_legacy': False}
)
proc.process()
workspace.save_mets()
# FIXME: add result assertions (find_files, parsing PAGE etc)

def test_run_legacy(self):
resolver = Resolver()
# with pushd_popd('/tmp/kraken-test') as tempdir:
with pushd_popd(tempdir=True) as tempdir:
workspace = resolver.workspace_from_url(assets.path_to('communist_manifesto/data/mets.xml'), dst_dir=tempdir, download=True)
proc = KrakenSegment(
workspace,
run_processor(
KrakenSegment,
workspace=workspace,
input_file_grp="OCR-D-IMG-BIN",
output_file_grp="OCR-D-SEG-LINE-KRAKEN",
parameter={'maxcolseps': 0, 'use_legacy': True}
)
proc.process()
workspace.save_mets()
# FIXME: add result assertions (find_files, parsing PAGE etc)

if __name__ == "__main__":
main(__file__)

0 comments on commit 712d1d3

Please sign in to comment.