π Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
Fix LoadImage class bug
SWHL8e2508e0a667
diff --git a/python/rapidocr_onnxruntime/__init__.py b/python/rapidocr_onnxruntime/__init__.pyindex 6522633..fd53856 100644--- a/python/rapidocr_onnxruntime/__init__.py+++ b/python/rapidocr_onnxruntime/__init__.py@@ -2,3 +2,4 @@# @Author: SWHL# @Contact: [email protected]from .rapid_ocr_api import RapidOCR+from .utils import LoadImageErrordiff --git a/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.py b/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.pyindex 4e01443..d6abdac 100644--- a/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.py+++ b/python/rapidocr_onnxruntime/ch_ppocr_v2_cls/text_cls.py@@ -20,8 +20,9 @@ from typing import Listimport cv2import numpy as np+from rapidocr_onnxruntime.utils import OrtInferSession, read_yaml+from .utils import ClsPostProcess-from rapidocr_onnxruntime.utils import read_yaml, OrtInferSessionclass TextClassifier():diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v3_det/text_detect.py b/python/rapidocr_onnxruntime/ch_ppocr_v3_det/text_detect.pyindex 6d8b6b6..99f7a00 100644--- a/python/rapidocr_onnxruntime/ch_ppocr_v3_det/text_detect.py+++ b/python/rapidocr_onnxruntime/ch_ppocr_v3_det/text_detect.py@@ -20,8 +20,9 @@ import timeimport cv2import numpy as np+from rapidocr_onnxruntime.utils import OrtInferSession, read_yaml+from .utils import DBPostProcess, create_operators, transform-from rapidocr_onnxruntime.utils import read_yaml, OrtInferSessionclass TextDetector():diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.pyindex 953d42a..1ce14a6 100644--- a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py+++ b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py@@ -19,8 +19,9 @@ from typing import Listimport cv2import numpy as np+from rapidocr_onnxruntime.utils import OrtInferSession, read_yaml+from .utils import CTCLabelDecode-from rapidocr_onnxruntime.utils import read_yaml, OrtInferSessionclass TextRecognizer():diff --git a/python/rapidocr_onnxruntime/utils.py b/python/rapidocr_onnxruntime/utils.pyindex abf0ce9..2dad7e9 100644--- a/python/rapidocr_onnxruntime/utils.py+++ b/python/rapidocr_onnxruntime/utils.py@@ -3,7 +3,6 @@# @Contact: [email protected]import argparseimport warnings-from io import BytesIOfrom pathlib import Pathfrom typing import Union@@ -61,7 +60,7 @@ class OrtInferSession():try:return self.session.run(self.get_output_names(), input_dict)except Exception as e:- raise ONNXRuntimeError('ONNXRuntime inferece failed.') from e+ raise ONNXRuntimeError('ONNXRuntime inference failed.') from edef get_input_names(self, ):return [v.name for v in self.session.get_inputs()]@@ -115,13 +114,16 @@ class LoadImage():self.verify_exist(img)try:img = np.array(Image.open(img))+ img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)except UnidentifiedImageError as e:raise LoadImageError(f'cannot identify image file {img}') from ereturn imgif isinstance(img, bytes):- return np.array(Image.open(BytesIO(img)))+ img = np.frombuffer(img, dtype=np.uint8)+ img = cv2.imdecode(img, cv2.IMREAD_COLOR)+ return imgif isinstance(img, np.ndarray):return imgdiff --git a/python/rapidocr_openvino/__init__.py b/python/rapidocr_openvino/__init__.pyindex 5a34512..fd53856 100644--- a/python/rapidocr_openvino/__init__.py+++ b/python/rapidocr_openvino/__init__.py@@ -1,4 +1,5 @@# -*- encoding: utf-8 -*-# @Author: SWHL# @Contact: [email protected]-from .rapid_ocr_api import RapidOCR\ No newline at end of file+from .rapid_ocr_api import RapidOCR+from .utils import LoadImageErrordiff --git a/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py b/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.pyindex cdbcbd8..a397d35 100644--- a/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py+++ b/python/rapidocr_openvino/ch_ppocr_v2_cls/text_cls.py@@ -20,8 +20,9 @@ from typing import Listimport cv2import numpy as np+from rapidocr_openvino.utils import OpenVINOInferSession, read_yaml+from .utils import ClsPostProcess-from rapidocr_openvino.utils import read_yaml, OpenVINOInferSessionclass TextClassifier():diff --git a/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.py b/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.pyindex 439f326..5c50cbb 100644--- a/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.py+++ b/python/rapidocr_openvino/ch_ppocr_v3_det/text_detect.py@@ -18,8 +18,9 @@ import timeimport cv2import numpy as np+from rapidocr_openvino.utils import OpenVINOInferSession, read_yaml+from .utils import DBPostProcess, create_operators, transform-from rapidocr_openvino.utils import read_yaml, OpenVINOInferSessionclass TextDetector():diff --git a/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.py b/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.pyindex 0a6d497..1bf6bb0 100644--- a/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.py+++ b/python/rapidocr_openvino/ch_ppocr_v3_rec/text_recognize.py@@ -17,14 +17,15 @@import argparseimport mathimport time-from typing import Listfrom pathlib import Path+from typing import Listimport cv2import numpy as np+from rapidocr_openvino.utils import OpenVINOInferSession, read_yaml+from .utils import CTCLabelDecode-from rapidocr_openvino.utils import read_yaml, OpenVINOInferSessionclass TextRecognizer():diff --git a/python/rapidocr_openvino/utils.py b/python/rapidocr_openvino/utils.pyindex c9b69e2..cdef222 100644--- a/python/rapidocr_openvino/utils.py+++ b/python/rapidocr_openvino/utils.py@@ -2,7 +2,6 @@# @Author: SWHL# @Contact: [email protected]import argparse-from io import BytesIOfrom pathlib import Pathfrom typing import Union@@ -63,13 +62,16 @@ class LoadImage():self.verify_exist(img)try:img = np.array(Image.open(img))+ img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)except UnidentifiedImageError as e:raise LoadImageError(f'cannot identify image file {img}') from ereturn imgif isinstance(img, bytes):- return np.array(Image.open(BytesIO(img)))+ img = np.frombuffer(img, dtype=np.uint8)+ img = cv2.imdecode(img, cv2.IMREAD_COLOR)+ return imgif isinstance(img, np.ndarray):return imgdiff --git a/python/tests/test_all_ort.py b/python/tests/test_all_ort.pyindex 08ba888..6267c41 100644--- a/python/tests/test_all_ort.py+++ b/python/tests/test_all_ort.py@@ -10,10 +10,10 @@ import pytestroot_dir = Path(__file__).resolve().parent.parent+print(root_dir)sys.path.append(str(root_dir))-from rapidocr_onnxruntime import RapidOCR-from rapidocr_onnxruntime.utils import LoadImageError+from rapidocr_onnxruntime import RapidOCR, LoadImageErrorrapid_ocr = RapidOCR()tests_dir = root_dir / 'tests' / 'test_files'diff --git a/python/tests/test_all_vino.py b/python/tests/test_all_vino.pyindex c222c22..5551632 100644--- a/python/tests/test_all_vino.py+++ b/python/tests/test_all_vino.py@@ -12,8 +12,7 @@ import pytestroot_dir = Path(__file__).resolve().parent.parentsys.path.append(str(root_dir))-from rapidocr_openvino import RapidOCR-from rapidocr_openvino.utils import LoadImageError+from rapidocr_openvino import RapidOCR, LoadImageErrorrapid_ocr = RapidOCR()