From 42303faa3e46c95a2832909f6f5661a6f9c60ff3 Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Fri, 2 Feb 2024 15:44:27 +0100 Subject: [PATCH] Handle no text detected for Google Vision and Azure --- owocr/ocr.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/owocr/ocr.py b/owocr/ocr.py index 9c3cd63..65132ee 100644 --- a/owocr/ocr.py +++ b/owocr/ocr.py @@ -167,7 +167,8 @@ class GoogleVision: except: return (False, 'Unknown error!') texts = response.text_annotations - x = (True, texts[0].description) + res = texts[0].description if len(texts) > 0 else '' + x = (True, res) return x def _preprocess(self, img): @@ -379,8 +380,9 @@ class AzureImageAnalysis: res = '' if read_result.read: - for line in read_result.read.blocks[0].lines: - res += line.text + ' ' + for block in read_result.read.blocks: + for line in block.lines: + res += line.text + ' ' else: return (False, 'Unknown error!')