Skip to content

Commit

Permalink
Merge pull request #11 from OCR-D/altimage-comments
Browse files Browse the repository at this point in the history
🐛 typo: comment{,s}, fix #8
  • Loading branch information
cneud committed Oct 23, 2020
2 parents c7e8e49 + c4b63fc commit 4d145cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sbb_binarize/ocrd_cli.py
Expand Up @@ -57,7 +57,7 @@ def process(self):

oplevel = self.parameter['operation_level']
model_path = self.parameter['model'] # pylint: disable=attribute-defined-outside-init
binarizer = SbbBinarizer(model_dir=model_path)
binarizer = SbbBinarizer(model_dir=model_path, logger=LOG)

for n, input_file in enumerate(self.input_files):
file_id = make_file_id(input_file, self.output_file_grp)
Expand All @@ -77,7 +77,7 @@ def process(self):
file_id + '.IMG-BIN',
page_id=input_file.pageId,
file_grp=self.output_file_grp)
page.add_AlternativeImage(AlternativeImageType(filename=bin_image_path, comment='%s,binarized' % page_xywh['features']))
page.add_AlternativeImage(AlternativeImageType(filename=bin_image_path, comments='%s,binarized' % page_xywh['features']))

elif oplevel == 'region':
regions = page.get_AllRegions(['Text', 'Table'], depth=1)
Expand Down
8 changes: 6 additions & 2 deletions sbb_binarize/sbb_binarize.py
Expand Up @@ -18,13 +18,16 @@
sys.stderr = stderr
import tensorflow as tf

import logging

def resize_image(img_in, input_height, input_width):
return cv2.resize(img_in, (input_width, input_height), interpolation=cv2.INTER_NEAREST)

class SbbBinarizer:

def __init__(self, model_dir):
def __init__(self, model_dir, logger=None):
self.model_dir = model_dir
self.log = logger if logger else logging.getLogger('SbbBinarizer')

def start_new_session(self):
config = tf.ConfigProto()
Expand Down Expand Up @@ -194,7 +197,8 @@ def run(self, image=None, image_path=None, save=None, use_patches=False):
self.start_new_session()
list_of_model_files = glob('%s/*.h5' % self.model_dir)
img_last = 0
for model_in in list_of_model_files:
for n, model_in in enumerate(list_of_model_files):
self.log.info('Predicting with model %s [%s/%s]' % (model_in, n + 1, len(list_of_model_files)))

res = self.predict(model_in, image, use_patches)

Expand Down

0 comments on commit 4d145cc

Please sign in to comment.