From c3949794ba83a154e5a4c43158f1a554ea23964f Mon Sep 17 00:00:00 2001 From: test123456654321 <16307130148@fudan.edu.cn> Date: Sat, 26 Oct 2024 12:27:19 +0800 Subject: [PATCH] nores --- src/LunaTranslator/myutils/ocrutil.py | 2 ++ src/LunaTranslator/ocrengines/baseocrclass.py | 2 +- src/LunaTranslator/ocrengines/googlelens.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/LunaTranslator/myutils/ocrutil.py b/src/LunaTranslator/myutils/ocrutil.py index cc9da9c4..e5880aa9 100644 --- a/src/LunaTranslator/myutils/ocrutil.py +++ b/src/LunaTranslator/myutils/ocrutil.py @@ -90,6 +90,8 @@ def ocr_run(qimage: QImage): try: ocr_init() res = _ocrengine._private_ocr(image) + if not res: + return "", None gobject.baseobject.maybesetocrresult(res) text = res["textonly"] if res["isocrtranslate"]: diff --git a/src/LunaTranslator/ocrengines/baseocrclass.py b/src/LunaTranslator/ocrengines/baseocrclass.py index a4a96d98..7deeb9e3 100644 --- a/src/LunaTranslator/ocrengines/baseocrclass.py +++ b/src/LunaTranslator/ocrengines/baseocrclass.py @@ -129,7 +129,7 @@ class baseocr(commonbase): elif isinstance(text, (tuple, list)): text = {"text": text} elif not text: - text = {} + return boxs = text.get("box") texts = text.get("text") if not boxs: diff --git a/src/LunaTranslator/ocrengines/googlelens.py b/src/LunaTranslator/ocrengines/googlelens.py index 91d8327d..fb82c92b 100644 --- a/src/LunaTranslator/ocrengines/googlelens.py +++ b/src/LunaTranslator/ocrengines/googlelens.py @@ -36,4 +36,6 @@ class OCR(baseocr): res = "" text = lens_object["data"][3][4][0] + if len(text) == 0: + return return text[0]