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]