1
1
# pylint: disable=import-error
2
2
3
3
import json
4
+ import os
4
5
5
6
from ocrd import run_processor
7
+ from ocrd_utils import MIMETYPE_PAGE
8
+ from ocrd_models .constants import NAMESPACES
9
+ from ocrd_modelfactory import page_from_file
10
+
6
11
from ocrd_kraken .binarize import KrakenBinarize
7
12
8
13
from .assets import assets
9
14
10
15
11
16
PARAM_JSON = assets .url_of ('param-binarize.json' )
12
17
18
+ def analyse_result (ws , level ):
19
+ assert os .path .isdir (os .path .join (ws .directory , 'OCR-D-BIN-KRAKEN' ))
20
+ out_files = list (ws .find_files (fileGrp = "OCR-D-BIN-KRAKEN" , mimetype = MIMETYPE_PAGE ))
21
+ assert len (out_files ), "found no output PAGE file"
22
+ out_images = list (ws .find_files (fileGrp = "OCR-D-BIN-KRAKEN" , mimetype = "//^image/.*" ))
23
+ assert len (out_images ), "found no output image file"
24
+ out_pcgts = page_from_file (out_files [0 ])
25
+ assert out_pcgts is not None
26
+ out_images = out_pcgts .etree .xpath ('//page:%s/page:AlternativeImage[contains(@comments,"binarized")]' % level , namespaces = NAMESPACES )
27
+ assert len (out_images ) > 0 , "found no binarized AlternativeImages in output PAGE file"
28
+
13
29
def test_param_json (workspace_sbb ):
14
30
run_processor (KrakenBinarize ,
15
31
input_file_grp = "OCR-D-IMG" ,
@@ -19,6 +35,7 @@ def test_param_json(workspace_sbb):
19
35
)
20
36
ws = workspace_sbb ['workspace' ]
21
37
ws .save_mets ()
38
+ analyse_result (ws , 'Page' )
22
39
23
40
def test_binarize_regions (workspace_aufklaerung ):
24
41
run_processor (KrakenBinarize ,
@@ -29,7 +46,7 @@ def test_binarize_regions(workspace_aufklaerung):
29
46
)
30
47
ws = workspace_aufklaerung ['workspace' ]
31
48
ws .save_mets ()
32
- # FIXME: add result assertions (find_files, parsing PAGE etc )
49
+ analyse_result ( ws , 'TextRegion' )
33
50
34
51
def test_binarize_lines (workspace_aufklaerung ):
35
52
run_processor (KrakenBinarize ,
@@ -40,4 +57,5 @@ def test_binarize_lines(workspace_aufklaerung):
40
57
)
41
58
ws = workspace_aufklaerung ['workspace' ]
42
59
ws .save_mets ()
43
- # FIXME: add result assertions (find_files, parsing PAGE etc)
60
+ analyse_result (ws , 'TextLine' )
61
+
0 commit comments