Skip to content

Commit fb6cb47

Browse files
authored
Merge pull request #69 from kba/getlogger
getLogger per method
2 parents c361dbb + ff99d9a commit fb6cb47

File tree

9 files changed

+23
-9
lines changed

9 files changed

+23
-9
lines changed

ocrd_cis/ocrd-tool.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"git_url": "https://github.com/cisocrgroup/ocrd_cis",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"tools": {
55
"ocrd-cis-ocropy-binarize": {
66
"executable": "ocrd-cis-ocropy-binarize",

ocrd_cis/ocropy/binarize.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
#sys.path.append(os.path.dirname(os.path.abspath(__file__)))
3232

3333
TOOL = 'ocrd-cis-ocropy-binarize'
34-
LOG = getLogger('processor.OcropyBinarize')
3534

3635
def binarize(pil_image, method='ocropy', maxskew=2, threshold=0.5, nrm=False, zoom=1.0):
36+
LOG = getLogger('processor.OcropyBinarize')
3737
LOG.debug('binarizing %dx%d image with method=%s', pil_image.width, pil_image.height, method)
3838
if method == 'none':
3939
# useful if the images are already binary,
@@ -76,6 +76,7 @@ def __init__(self, *args, **kwargs):
7676
kwargs['ocrd_tool'] = self.ocrd_tool['tools'][TOOL]
7777
kwargs['version'] = self.ocrd_tool['version']
7878
super(OcropyBinarize, self).__init__(*args, **kwargs)
79+
LOG = getLogger('processor.OcropyBinarize')
7980
if hasattr(self, 'output_file_grp'):
8081
if self.parameter['grayscale'] and self.parameter['method'] != 'ocropy':
8182
LOG.critical('requested method %s does not support grayscale normalized output',
@@ -104,6 +105,7 @@ def process(self):
104105
105106
Produce a new output file by serialising the resulting hierarchy.
106107
"""
108+
LOG = getLogger('processor.OcropyBinarize')
107109
level = self.parameter['level-of-operation']
108110
assert_file_grp_cardinality(self.input_file_grp, 1)
109111
assert_file_grp_cardinality(self.output_file_grp, 1)
@@ -181,6 +183,7 @@ def process(self):
181183
file_id, self.output_file_grp, out.local_filename)
182184

183185
def process_page(self, page, page_image, page_xywh, zoom, page_id, file_id):
186+
LOG = getLogger('processor.OcropyBinarize')
184187
LOG.info("About to binarize page '%s'", page_id)
185188
features = page_xywh['features']
186189
if 'angle' in page_xywh and page_xywh['angle']:
@@ -226,6 +229,7 @@ def process_page(self, page, page_image, page_xywh, zoom, page_id, file_id):
226229
comments=features))
227230

228231
def process_region(self, region, region_image, region_xywh, zoom, page_id, file_id):
232+
LOG = getLogger('processor.OcropyBinarize')
229233
LOG.info("About to binarize page '%s' region '%s'", page_id, region.id)
230234
features = region_xywh['features']
231235
if 'angle' in region_xywh and region_xywh['angle']:
@@ -273,6 +277,7 @@ def process_region(self, region, region_image, region_xywh, zoom, page_id, file_
273277
comments=features))
274278

275279
def process_line(self, line, line_image, line_xywh, zoom, page_id, region_id, file_id):
280+
LOG = getLogger('processor.OcropyBinarize')
276281
LOG.info("About to binarize page '%s' region '%s' line '%s'",
277282
page_id, region_id, line.id)
278283
features = line_xywh['features']

ocrd_cis/ocropy/clip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
)
3636

3737
TOOL = 'ocrd-cis-ocropy-clip'
38-
LOG = getLogger('processor.OcropyClip')
3938

4039
class OcropyClip(Processor):
4140

@@ -80,6 +79,7 @@ def process(self):
8079
# too. However, region-level clipping _must_ be run before region-level
8180
# deskewing, because that would make segments incomensurable with their
8281
# neighbours.
82+
LOG = getLogger('processor.OcropyClip')
8383
level = self.parameter['level-of-operation']
8484
assert_file_grp_cardinality(self.input_file_grp, 1)
8585
assert_file_grp_cardinality(self.output_file_grp, 1)
@@ -226,6 +226,7 @@ def process(self):
226226
def process_segment(self, segment, segment_mask, segment_polygon, neighbours,
227227
background_image, parent_image, parent_coords, parent_bin,
228228
page_id, file_id):
229+
LOG = getLogger('processor.OcropyClip')
229230
# initialize AlternativeImage@comments classes from parent, except
230231
# for those operations that can apply on multiple hierarchy levels:
231232
features = ','.join(

ocrd_cis/ocropy/denoise.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
remove_noise)
2323

2424
TOOL = 'ocrd-cis-ocropy-denoise'
25-
LOG = getLogger('processor.OcropyDenoise')
2625

2726
class OcropyDenoise(Processor):
2827

@@ -53,6 +52,7 @@ def process(self):
5352
5453
Produce a new output file by serialising the resulting hierarchy.
5554
"""
55+
LOG = getLogger('processor.OcropyDenoise')
5656
level = self.parameter['level-of-operation']
5757
assert_file_grp_cardinality(self.input_file_grp, 1)
5858
assert_file_grp_cardinality(self.output_file_grp, 1)
@@ -133,6 +133,7 @@ def process(self):
133133
file_id, self.output_file_grp, out.local_filename)
134134

135135
def process_segment(self, segment, segment_image, segment_xywh, zoom, page_id, file_id):
136+
LOG = getLogger('processor.OcropyDenoise')
136137
LOG.info("About to despeckle '%s'", file_id)
137138
bin_image = remove_noise(segment_image,
138139
maxsize=self.parameter['noise_maxsize']/zoom*300/72) # in pt

ocrd_cis/ocropy/deskew.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#sys.path.append(os.path.dirname(os.path.abspath(__file__)))
2727

2828
TOOL = 'ocrd-cis-ocropy-deskew'
29-
LOG = getLogger('processor.OcropyDeskew')
3029

3130
def deskew(pil_image, maxskew=2):
3231
array = pil2array(pil_image)
@@ -59,6 +58,7 @@ def process(self):
5958
6059
Produce a new output file by serialising the resulting hierarchy.
6160
"""
61+
LOG = getLogger('processor.OcropyDeskew')
6262
level = self.parameter['level-of-operation']
6363
assert_file_grp_cardinality(self.input_file_grp, 1)
6464
assert_file_grp_cardinality(self.output_file_grp, 1)
@@ -124,6 +124,7 @@ def process(self):
124124
file_id, self.output_file_grp, out.local_filename)
125125

126126
def _process_segment(self, segment, segment_image, segment_coords, segment_id, page_id, file_id):
127+
LOG = getLogger('processor.OcropyDeskew')
127128
angle0 = segment_coords['angle'] # deskewing (w.r.t. top image) already applied to segment_image
128129
LOG.info("About to deskew %s", segment_id)
129130
angle = deskew(segment_image, maxskew=self.parameter['maxskew']) # additional angle to be applied

ocrd_cis/ocropy/dewarp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#sys.path.append(os.path.dirname(os.path.abspath(__file__)))
2828

2929
TOOL = 'ocrd-cis-ocropy-dewarp'
30-
LOG = getLogger('processor.OcropyDewarp')
3130

3231
class InvalidLine(Exception):
3332
"""Line image does not allow dewarping and should be ignored."""
@@ -100,6 +99,7 @@ def process(self):
10099
101100
Produce a new output file by serialising the resulting hierarchy.
102101
"""
102+
LOG = getLogger('processor.OcropyDewarp')
103103
assert_file_grp_cardinality(self.input_file_grp, 1)
104104
assert_file_grp_cardinality(self.output_file_grp, 1)
105105

ocrd_cis/ocropy/recognize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
)
3333

3434
TOOL = 'ocrd-cis-ocropy-recognize'
35-
LOG = getLogger('processor.OcropyRecognize')
3635

3736
def resize_keep_ratio(image, baseheight=48):
3837
scale = baseheight / image.height
@@ -132,6 +131,7 @@ def process(self):
132131
133132
Produce a new output file by serialising the resulting hierarchy.
134133
"""
134+
LOG = getLogger('processor.OcropyRecognize')
135135

136136
assert_file_grp_cardinality(self.input_file_grp, 1)
137137
assert_file_grp_cardinality(self.output_file_grp, 1)
@@ -191,6 +191,7 @@ def process(self):
191191
file_id, self.output_file_grp, out.local_filename)
192192

193193
def process_regions(self, regions, maxlevel, page_image, page_coords):
194+
LOG = getLogger('processor.OcropyRecognize')
194195
edits = 0
195196
lengs = 0
196197
for region in regions:
@@ -214,6 +215,7 @@ def process_regions(self, regions, maxlevel, page_image, page_coords):
214215
LOG.info('CER: %.1f%%', 100.0 * edits / lengs)
215216

216217
def process_lines(self, textlines, maxlevel, region_image, region_coords):
218+
LOG = getLogger('processor.OcropyRecognize')
217219
edits = 0
218220
lengs = 0
219221
for line in textlines:

ocrd_cis/ocropy/resegment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838

3939
TOOL = 'ocrd-cis-ocropy-resegment'
40-
LOG = getLogger('processor.OcropyResegment')
4140

4241
def resegment(line_polygon, region_labels, region_bin, line_id,
4342
extend_margins=3,
@@ -57,6 +56,7 @@ def resegment(line_polygon, region_labels, region_bin, line_id,
5756
If ``extend_margins`` is larger than zero, then extend ``line_polygon``
5857
by that amount of pixels horizontally and vertically before.
5958
"""
59+
LOG = getLogger('processor.OcropyResegment')
6060
# height, width = region_labels.shape
6161
# mask from line polygon:
6262
line_mask = np.zeros_like(region_labels)
@@ -144,6 +144,7 @@ def process(self):
144144
145145
Produce a new output file by serialising the resulting hierarchy.
146146
"""
147+
LOG = getLogger('processor.OcropyResegment')
147148
# This makes best sense for bad/coarse line segmentation, like current GT
148149
# or as postprocessing for bbox-only steps.
149150
# Most notably, it can convert rectangles to polygons (polygonalization).

ocrd_cis/ocropy/segment.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
)
5656

5757
TOOL = 'ocrd-cis-ocropy-segment'
58-
LOG = getLogger('processor.OcropySegment')
5958

6059
def masks2polygons(bg_labels, fg_bin, name, min_area=None, simplify=False):
6160
"""Convert label masks into polygon coordinates.
@@ -71,6 +70,7 @@ def masks2polygons(bg_labels, fg_bin, name, min_area=None, simplify=False):
7170
7271
Return these polygons as a list of label, polygon tuples.
7372
"""
73+
LOG = getLogger('processor.OcropySegment')
7474
results = list()
7575
for label in np.unique(bg_labels):
7676
if not label:
@@ -197,6 +197,7 @@ def process(self):
197197
198198
Produce a new output file by serialising the resulting hierarchy.
199199
"""
200+
LOG = getLogger('processor.OcropySegment')
200201
# FIXME: allow passing a-priori info on reading order / textline order
201202
# (and then pass on as ``bt`` and ``rl``; however, there may be a mixture
202203
# of different scripts; also, vertical writing needs internal rotation
@@ -412,6 +413,7 @@ def _process_element(self, element, ignore, image, coords, element_id, file_id,
412413
in full page/table mode, then combine all separators among them with the
413414
newly detected separators to guide region segmentation.
414415
"""
416+
LOG = getLogger('processor.OcropySegment')
415417
element_array = pil2array(image)
416418
element_bin = np.array(element_array <= midrange(element_array), np.bool)
417419
sep_bin = np.zeros_like(element_bin, np.bool)
@@ -763,6 +765,7 @@ def page_subgroup_in_reading_order(roelem):
763765
764766
Return the new group object.
765767
"""
768+
LOG = getLogger('processor.OcropySegment')
766769
if not roelem:
767770
LOG.error('Cannot subgroup from empty ReadingOrder element')
768771
return roelem

0 commit comments

Comments
 (0)