|
|
@ -1,60 +1,50 @@
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
from os.path import join, exists
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
import urllib.request
|
|
|
|
|
|
|
|
|
|
|
|
from test.base import TestCase, main, assets, skip
|
|
|
|
from test.base import TestCase, main, assets, skip
|
|
|
|
|
|
|
|
|
|
|
|
from ocrd.resolver import Resolver
|
|
|
|
from ocrd.resolver import Resolver
|
|
|
|
|
|
|
|
|
|
|
|
from ocrd_tesserocr import TesserocrSegmentRegion
|
|
|
|
|
|
|
|
from ocrd_tesserocr import TesserocrSegmentLine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ocrd_calamari import CalamariRecognize
|
|
|
|
from ocrd_calamari import CalamariRecognize
|
|
|
|
|
|
|
|
|
|
|
|
#METS_HEROLD_SMALL = assets.url_of('SBB0000F29300010000/data/mets_one_file.xml')
|
|
|
|
METS_KANT = assets.url_of('kant_aufklaerung_1784-page-block-line-word_glyph/data/mets.xml')
|
|
|
|
# as long as #96 remains, we cannot use workspaces which have local relative files:
|
|
|
|
|
|
|
|
METS_HEROLD_SMALL = assets.url_of('kant_aufklaerung_1784-binarized/data/mets.xml')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WORKSPACE_DIR = '/tmp/test-ocrd-calamari'
|
|
|
|
WORKSPACE_DIR = '/tmp/test-ocrd-calamari'
|
|
|
|
|
|
|
|
|
|
|
|
class TestCalamariRecognize(TestCase):
|
|
|
|
class TestCalamariRecognize(TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
|
if exists(WORKSPACE_DIR):
|
|
|
|
if os.path.exists(WORKSPACE_DIR):
|
|
|
|
shutil.rmtree(WORKSPACE_DIR)
|
|
|
|
shutil.rmtree(WORKSPACE_DIR)
|
|
|
|
os.makedirs(WORKSPACE_DIR)
|
|
|
|
os.makedirs(WORKSPACE_DIR)
|
|
|
|
|
|
|
|
|
|
|
|
#skip("Takes too long")
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
def runTest(self):
|
|
|
|
resolver = Resolver()
|
|
|
|
resolver = Resolver()
|
|
|
|
workspace = resolver.workspace_from_url(METS_HEROLD_SMALL, dst_dir=WORKSPACE_DIR)
|
|
|
|
workspace = resolver.workspace_from_url(METS_KANT, dst_dir=WORKSPACE_DIR)
|
|
|
|
|
|
|
|
|
|
|
|
TesserocrSegmentRegion(
|
|
|
|
# XXX Work around data bug(?):
|
|
|
|
workspace,
|
|
|
|
# PAGE-XML links to OCR-D-IMG/INPUT_0017.tif, but this is nothing core can download
|
|
|
|
input_file_grp="OCR-D-IMG",
|
|
|
|
os.makedirs(os.path.join(WORKSPACE_DIR, 'OCR-D-IMG'))
|
|
|
|
output_file_grp="OCR-D-SEG-BLOCK"
|
|
|
|
for f in ['INPUT_0017.tif', 'INPUT_0020.tif']:
|
|
|
|
).process()
|
|
|
|
urllib.request.urlretrieve(
|
|
|
|
workspace.save_mets()
|
|
|
|
"https://github.com/OCR-D/assets/raw/master/data/kant_aufklaerung_1784/data/OCR-D-IMG/" + f,
|
|
|
|
|
|
|
|
os.path.join(WORKSPACE_DIR, 'OCR-D-IMG', f))
|
|
|
|
|
|
|
|
|
|
|
|
TesserocrSegmentLine(
|
|
|
|
# XXX Should remove GT text to really test this
|
|
|
|
workspace,
|
|
|
|
|
|
|
|
input_file_grp="OCR-D-SEG-BLOCK",
|
|
|
|
|
|
|
|
output_file_grp="OCR-D-SEG-LINE"
|
|
|
|
|
|
|
|
).process()
|
|
|
|
|
|
|
|
workspace.save_mets()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CalamariRecognize(
|
|
|
|
CalamariRecognize(
|
|
|
|
workspace,
|
|
|
|
workspace,
|
|
|
|
input_file_grp="OCR-D-SEG-LINE",
|
|
|
|
input_file_grp="OCR-D-GT-SEG-LINE",
|
|
|
|
output_file_grp="OCR-D-OCR-CALAMARI",
|
|
|
|
output_file_grp="OCR-D-OCR-CALAMARI",
|
|
|
|
parameter={
|
|
|
|
parameter={
|
|
|
|
'checkpoint': 'calamari_models/fraktur_historical/*.ckpt.json'
|
|
|
|
'checkpoint': os.path.join(os.getcwd(), 'calamari_models/fraktur_19th_century/*.ckpt.json')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
).process()
|
|
|
|
).process()
|
|
|
|
workspace.save_mets()
|
|
|
|
workspace.save_mets()
|
|
|
|
|
|
|
|
|
|
|
|
page1 = join(workspace.directory, 'OCR-D-OCR-CALAMARI/OCR-D-OCR-CALAMARI_0001.xml')
|
|
|
|
page1 = os.path.join(workspace.directory, 'OCR-D-OCR-CALAMARI/OCR-D-OCR-CALAMARI_0001.xml')
|
|
|
|
self.assertTrue(exists(page1))
|
|
|
|
self.assertTrue(os.path.exists(page1))
|
|
|
|
with open(page1, 'r') as f:
|
|
|
|
with open(page1, 'r') as f:
|
|
|
|
self.assertIn('verſchuldeten', f.read())
|
|
|
|
self.assertIn('verſchuldeten', f.read())
|
|
|
|
|
|
|
|
|
|
|
|