π Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
Remove invalid function
SWHL50ce26671ab4
diff --git a/python/demo.py b/python/demo.pyindex 5449c28..60a91e1 100644--- a/python/demo.py+++ b/python/demo.py@@ -8,9 +8,10 @@ from pathlib import Pathimport cv2import numpy as npfrom PIL import Image, ImageDraw, ImageFont-from rapidocr_openvino import RapidOCR-# from rapidocr_onnxruntime import RapidOCR+from rapidocr_onnxruntime import RapidOCR++# from rapidocr_openvino import RapidOCRdef draw_ocr_box_txt(image, boxes, txts, font_path, scores=None, text_score=0.5):@@ -21,6 +22,9 @@ def draw_ocr_box_txt(image, boxes, txts, font_path, scores=None, text_score=0.5))h, w = image.height, image.width+ if image.mode == "L":+ image = image.convert("RGB")+img_left = image.copy()img_right = Image.new("RGB", (w, h), (255, 255, 255))@@ -95,9 +99,11 @@ def visualize(image_path, result, font_path="resources/fonts/FZYTK.TTF"):if __name__ == "__main__":rapid_ocr = RapidOCR()- image_path = "tests/test_files/ch_en_num.jpg"- with open(image_path, "rb") as f:- img = f.read()+ image_path = "res.png"+ # with open(image_path, "rb") as f:+ # img = f.read()+ img = cv2.imread(image_path)+ img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)result, elapse_list = rapid_ocr(img)print(result)print(elapse_list)diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py b/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.pyindex 3b08e07..e1155c1 100644--- a/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py+++ b/python/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py@@ -21,51 +21,16 @@ import sysimport cv2import numpy as npimport pyclipper-import sixfrom shapely.geometry import Polygon-class DecodeImage:- """decode image"""-- def __init__(self, img_mode="RGB", channel_first=False):- self.img_mode = img_mode- self.channel_first = channel_first-- def __call__(self, data):- img = data["image"]- if six.PY2:- assert (- type(img) is str and len(img) > 0- ), "invalid input 'img' in DecodeImage"- else:- assert (- type(img) is bytes and len(img) > 0- ), "invalid input 'img' in DecodeImage"-- img = np.frombuffer(img, dtype="uint8")- img = cv2.imdecode(img, 1)- if img is None:- return None-- if self.img_mode == "GRAY":- img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)- elif self.img_mode == "RGB":- assert img.shape[2] == 3, f"invalid shape of image[{img.shape}]"- img = img[:, :, ::-1]-- if self.channel_first:- img = img.transpose((2, 0, 1))- data["image"] = img- return data--class NormalizeImage:"""normalize image such as substract mean, divide std"""def __init__(self, scale=None, mean=None, std=None, order="chw"):if isinstance(scale, str):scale = eval(scale)+self.scale = np.float32(scale if scale is not None else 1.0 / 255.0)mean = mean if mean is not None else [0.485, 0.456, 0.406]std = std if std is not None else [0.229, 0.224, 0.225]@@ -105,7 +70,6 @@ class KeepKeys:class DetResizeForTest:def __init__(self, **kwargs):- super(DetResizeForTest, self).__init__()self.resize_type = 0if "image_shape" in kwargs:self.image_shape = kwargs["image_shape"]@@ -126,13 +90,12 @@ class DetResizeForTest:src_h, src_w = img.shape[:2]if self.resize_type == 0:- # img, shape = self.resize_image_type0(img)img, [ratio_h, ratio_w] = self.resize_image_type0(img)elif self.resize_type == 2:img, [ratio_h, ratio_w] = self.resize_image_type2(img)else:- # img, shape = self.resize_image_type1(img)img, [ratio_h, ratio_w] = self.resize_image_type1(img)+data["image"] = imgdata["shape"] = np.array([src_h, src_w, ratio_h, ratio_w])return data@@ -143,7 +106,6 @@ class DetResizeForTest:ratio_h = float(resize_h) / ori_hratio_w = float(resize_w) / ori_wimg = cv2.resize(img, (int(resize_w), int(resize_h)))- # return img, np.array([ori_h, ori_w])return img, [ratio_h, ratio_w]def resize_image_type0(self, img):@@ -174,6 +136,7 @@ class DetResizeForTest:ratio = float(limit_side_len) / welse:ratio = 1.0+resize_h = int(h * ratio)resize_w = int(w * ratio)@@ -187,6 +150,7 @@ class DetResizeForTest:except:print(img.shape, resize_w, resize_h)sys.exit(0)+ratio_h = resize_h / float(h)ratio_w = resize_w / float(w)return img, [ratio_h, ratio_w]diff --git a/python/rapidocr_openvino/ch_ppocr_v3_det/utils.py b/python/rapidocr_openvino/ch_ppocr_v3_det/utils.pyindex 2e586b7..89fbdc2 100644--- a/python/rapidocr_openvino/ch_ppocr_v3_det/utils.py+++ b/python/rapidocr_openvino/ch_ppocr_v3_det/utils.py@@ -21,45 +21,9 @@ import sysimport cv2import numpy as npimport pyclipper-import sixfrom shapely.geometry import Polygon-class DecodeImage:- """decode image"""-- def __init__(self, img_mode="RGB", channel_first=False):- self.img_mode = img_mode- self.channel_first = channel_first-- def __call__(self, data):- img = data["image"]- if six.PY2:- assert (- type(img) is str and len(img) > 0- ), "invalid input 'img' in DecodeImage"- else:- assert (- type(img) is bytes and len(img) > 0- ), "invalid input 'img' in DecodeImage"-- img = np.frombuffer(img, dtype="uint8")- img = cv2.imdecode(img, 1)- if img is None:- return None-- if self.img_mode == "GRAY":- img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)- elif self.img_mode == "RGB":- assert img.shape[2] == 3, f"invalid shape of image[{img.shape}]"- img = img[:, :, ::-1]-- if self.channel_first:- img = img.transpose((2, 0, 1))- data["image"] = img- return data--class NormalizeImage:"""normalize image such as substract mean, divide std"""