From b802b4deafb767a52cadc1c491a4bb78d766cbef Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Wed, 5 Feb 2020 13:07:56 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20configuring=20a=20cut=20off?= =?UTF-8?q?=20confidence=20value=20for=20glyph=20alternatives?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ ocrd_calamari/ocrd-tool.json | 6 ++++++ ocrd_calamari/recognize.py | 14 +++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 359f1a3..8ebbf4f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,9 @@ With `test-parameters.json`: } ~~~ +You may want to have a look at the [ocrd-tool.json](ocrd-tool.json) descriptions +for additional parameters and default values. + ## Development & Testing For information regarding development and testing, please see [README-DEV.md](README-DEV.md). diff --git a/ocrd_calamari/ocrd-tool.json b/ocrd_calamari/ocrd-tool.json index 1174243..b954d41 100644 --- a/ocrd_calamari/ocrd-tool.json +++ b/ocrd_calamari/ocrd-tool.json @@ -31,6 +31,12 @@ "enum": ["line", "word", "glyph"], "default": "line", "description": "Deepest PAGE XML hierarchy level to include TextEquiv results for" + }, + "glyph_conf_cutoff": { + "type": "number", + "format": "float", + "default": 0.001, + "description": "Only include glyph alternatives with confidences above this threshold" } } } diff --git a/ocrd_calamari/recognize.py b/ocrd_calamari/recognize.py index 7b2db0d..c588a62 100644 --- a/ocrd_calamari/recognize.py +++ b/ocrd_calamari/recognize.py @@ -148,13 +148,17 @@ class CalamariRecognize(Processor): glyph = GlyphType(id='%s_glyph%04d' % (word.id, glyph_no), Coords=CoordsType(points)) - chars = sorted(p.chars, key=lambda k: k.probability, reverse=True) + # Filter predictions + chars = p.chars + chars = [c for c in chars if c.char] # XXX Note that omission probabilities are not normalized?! + chars = [c for c in chars if c.probability >= self.parameter['glyph_conf_cutoff']] + + # Sort and add predictions (= TextEquivs) + chars = sorted(chars, key=lambda k: k.probability, reverse=True) char_index = 1 # Must start with 1, see https://ocr-d.github.io/page#multiple-textequivs for char in chars: - if char.char: - glyph.add_TextEquiv(TextEquivType(Unicode=char.char, index=char_index, conf=char.probability)) - char_index += 1 - # XXX Note that omission probabilities are not normalized?! + glyph.add_TextEquiv(TextEquivType(Unicode=char.char, index=char_index, conf=char.probability)) + char_index += 1 word.add_Glyph(glyph)