1
0
Fork 0
mirror of https://github.com/mikegerber/ocrd_calamari.git synced 2025-06-09 19:59:53 +02:00

Use GT segmentation to test

This commit is contained in:
Gerber, Mike 2019-12-03 16:23:41 +01:00
parent 5b15dc5fd6
commit d8212ced93
4 changed files with 22 additions and 30 deletions

View file

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