From 3e8fa659dc9b364305f602759181b5e1140f27b7 Mon Sep 17 00:00:00 2001 From: AuroraWright Date: Sun, 6 Apr 2025 15:46:35 +0200 Subject: [PATCH] Handle OneOCR errors --- README.md | 2 +- owocr/ocr.py | 15 +++++++++++---- pyproject.toml | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d9480f..0310ab6 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Additionally: - Apple Vision framework: this will work on macOS Ventura or later. In my experience, the best of the local providers for horizontal text ("a" key) - Apple Live Text (VisionKit framework): this will work on macOS Ventura or later. It should be the same as Vision except that in Sonoma Apple added vertical text reading ("d" key) - WinRT OCR: install with `pip install owocr[winocr]` on Windows 10 and later. It can also be used by installing winocr on a Windows virtual machine and running the server there (`winocr_serve`) and specifying the IP address of the Windows VM/machine in the config file ("w" key) -- OneOCR: install with `pip install owocr[oneocr]` on Windows 10 and later. In my experience it's pretty good, though not as much as the Apple one. You need to copy 3 system files from Windows 11 to use it, refer to the readme (here)[https://github.com/AuroraWright/oneocr] ("z" key) +- OneOCR: install with `pip install owocr[oneocr]` on Windows 10 and later. In my experience it's pretty good, though not as much as the Apple one. You need to copy 3 system files from Windows 11 to use it, refer to the readme [here](https://github.com/AuroraWright/oneocr) ("z" key) ## Cloud providers - Google Lens: Google Vision in disguise (no need for API keys!), install with `pip install owocr[lens]` ("l" key) diff --git a/owocr/ocr.py b/owocr/ocr.py index 1fae768..ce42e7a 100644 --- a/owocr/ocr.py +++ b/owocr/ocr.py @@ -730,9 +730,13 @@ class OneOCR: elif 'oneocr' not in sys.modules: logger.warning('oneocr not available, OneOCR will not work!') else: - self.model = oneocr.OcrEngine() - self.available = True - logger.info('OneOCR ready') + try: + self.model = oneocr.OcrEngine() + except RuntimeError as e: + logger.warning(e + ' , OneOCR will not work!') + else: + self.available = True + logger.info('OneOCR ready') else: try: self.url = config['url'] @@ -750,7 +754,10 @@ class OneOCR: raise ValueError(f'img_or_path must be a path or PIL.Image, instead got: {img_or_path}') if sys.platform == 'win32': - res = self.model.recognize_pil(img)['text'] + try: + res = self.model.recognize_pil(img)['text'] + except RuntimeError as e: + return (False, e) else: try: res = requests.post(self.url, data=self._preprocess(img), timeout=3) diff --git a/pyproject.toml b/pyproject.toml index a3b883c..500339d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "owocr" -version = "1.13.2" +version = "1.13.5" description = "Japanese OCR" readme = "README.md" requires-python = ">=3.11"