From cfb1fb2540ca2fb899d6ecf68ed9d328bed9e91e Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 26 Oct 2020 09:32:09 +0100 Subject: [PATCH 1/2] Try OCR on inverted line only if mean confidence is below 50 % The old code looked for the minimum confidence which triggered very often a 2nd OCR without improving the result. Signed-off-by: Stefan Weil --- src/lstm/lstmrecognizer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lstm/lstmrecognizer.cpp b/src/lstm/lstmrecognizer.cpp index 0d32504833..4baa10a27d 100644 --- a/src/lstm/lstmrecognizer.cpp +++ b/src/lstm/lstmrecognizer.cpp @@ -2,7 +2,6 @@ // File: lstmrecognizer.cpp // Description: Top-level line recognizer class for LSTM-based networks. // Author: Ray Smith -// Created: Thu May 02 10:59:06 PST 2013 // // (C) Copyright 2013, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -291,7 +290,7 @@ bool LSTMRecognizer::RecognizeLine(const ImageData& image_data, bool invert, // Check for auto inversion. float pos_min, pos_mean, pos_sd; OutputStats(*outputs, &pos_min, &pos_mean, &pos_sd); - if (invert && pos_min < 0.5) { + if (invert && pos_mean < 0.5) { // Run again inverted and see if it is any better. NetworkIO inv_inputs, inv_outputs; inv_inputs.set_int_mode(IsIntMode()); From eaf72ace3115aca7421c8c9ed34108e15360cf12 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 26 Oct 2020 20:37:47 +0100 Subject: [PATCH 2/2] Prefer result from inverted image if the mean confidence is better Signed-off-by: Stefan Weil --- src/lstm/lstmrecognizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lstm/lstmrecognizer.cpp b/src/lstm/lstmrecognizer.cpp index 4baa10a27d..37275528a7 100644 --- a/src/lstm/lstmrecognizer.cpp +++ b/src/lstm/lstmrecognizer.cpp @@ -302,7 +302,7 @@ bool LSTMRecognizer::RecognizeLine(const ImageData& image_data, bool invert, &inv_outputs); float inv_min, inv_mean, inv_sd; OutputStats(inv_outputs, &inv_min, &inv_mean, &inv_sd); - if (inv_min > pos_min && inv_mean > pos_mean && inv_sd < pos_sd) { + if (inv_mean > pos_mean) { // Inverted did better. Use inverted data. if (debug) { tprintf("Inverting image: old min=%g, mean=%g, sd=%g, inv %g,%g,%g\n",