π Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
ζ΄η代η
SWHLd8c45c8a0c69
diff --git a/python/ch_ppocr_mobile_v2_cls/text_cls.py b/python/ch_ppocr_mobile_v2_cls/text_cls.pyindex b226403..8992ec4 100755--- a/python/ch_ppocr_mobile_v2_cls/text_cls.py+++ b/python/ch_ppocr_mobile_v2_cls/text_cls.py@@ -121,12 +121,12 @@ class TextClassifier(object):if __name__ == "__main__":parser = argparse.ArgumentParser()- parser.add_argument('--image_dir', type=str, help='image_dir|image_path')- parser.add_argument('--cls_model_dir', type=str, help='cls_model_dir')+ parser.add_argument('--image_path', type=str, help='image_dir|image_path')+ parser.add_argument('--model_path', type=str, help='model_path')args = parser.parse_args()- text_classifier = TextClassifier(args.cls_model_dir)+ text_classifier = TextClassifier(args.model_path)- img_list, cls_res, predict_time = text_classifier(args.image_dir)+ img_list, cls_res, predict_time = text_classifier(args.image_path)for ino in range(len(img_list)):print(f"εη±»η»ζ:{cls_res[ino]}")diff --git a/python/ch_ppocr_mobile_v2_det/text_detect.py b/python/ch_ppocr_mobile_v2_det/text_detect.pyindex 0bf6163..e02fbff 100755--- a/python/ch_ppocr_mobile_v2_det/text_detect.py+++ b/python/ch_ppocr_mobile_v2_det/text_detect.py@@ -137,10 +137,8 @@ class TextDetector(object):if __name__ == "__main__":parser = argparse.ArgumentParser()- parser.add_argument('--image_path', type=str, default=None,- help='image_path|image_dir')- parser.add_argument('--model_path', type=str, default=None,- help='model_path')+ parser.add_argument('--image_path', type=str, help='image_path|image_dir')+ parser.add_argument('--model_path', type=str, help='model_path')args = parser.parse_args()text_detector = TextDetector(args.model_path)diff --git a/python/ch_ppocr_mobile_v2_rec/text_recognize.py b/python/ch_ppocr_mobile_v2_rec/text_recognize.pyindex 42a63db..53ec726 100755--- a/python/ch_ppocr_mobile_v2_rec/text_recognize.py+++ b/python/ch_ppocr_mobile_v2_rec/text_recognize.py@@ -32,23 +32,19 @@ root_path = Path(__file__).parentclass TextRecognizer(object):def __init__(self, rec_model_path):self.rec_image_shape = [3, 32, 320]- self.character_type = 'ch'self.rec_batch_num = 6- self.rec_algorithm = 'CRNN'self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')- self.use_space_char = True- self.postprocess_op = CTCLabelDecode(self.character_dict_path,- self.character_type,- self.use_space_char)+ self.postprocess_op = CTCLabelDecode(self.character_dict_path)self.session = onnxruntime.InferenceSession(rec_model_path)def resize_norm_img(self, img, max_wh_ratio):img_channel, img_height, img_width = self.rec_image_shapeassert img_channel == img.shape[2]- if self.character_type == "ch":- img_width = int((32 * max_wh_ratio))- max_wh_ratio = 1++ img_width = int((32 * max_wh_ratio))+ max_wh_ratio = 1+h, w = img.shape[:2]ratio = w / float(h)if math.ceil(img_height * ratio) > img_width:@@ -127,10 +123,10 @@ class TextRecognizer(object):if __name__ == "__main__":parser = argparse.ArgumentParser()- parser.add_argument('image_dir', type=str, help='image_dir|image_path')- parser.add_argument('model_path', type=str, help='rec_model_path')+ parser.add_argument('--image_path', type=str, help='image_dir|image_path')+ parser.add_argument('--model_path', type=str, help='rec_model_path')args = parser.parse_args()text_recognizer = TextRecognizer(args.model_path)- rec_res, predict_time = text_recognizer(args.image_dir)+ rec_res, predict_time = text_recognizer(args.image_path)print(f'θ―ε«η»ζ: {rec_res}\t cost: {predict_time}s')diff --git a/python/ch_ppocr_mobile_v2_rec/utils.py b/python/ch_ppocr_mobile_v2_rec/utils.pyindex 8836d71..d3b2c65 100755--- a/python/ch_ppocr_mobile_v2_rec/utils.py+++ b/python/ch_ppocr_mobile_v2_rec/utils.py@@ -1,7 +1,7 @@# !/usr/bin/env python# -*- encoding: utf-8 -*--# @File: PostProcess.py-# @Time: 2021/01/19 14:12:35+# @File: utils.py+# @Time: 2021/05/22 10:53:17# @Author: Maximport cv2import os@@ -9,35 +9,75 @@ import imghdrimport numpy as np-class BaseRecLabelDecode(object):+def get_image_file_list(img_file):+ imgs_lists = []+ if img_file is None or not os.path.exists(img_file):+ raise FileNotFoundError("not found any img file in {}".format(img_file))++ img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'GIF'}+ if os.path.isfile(img_file) and imghdr.what(img_file) in img_end:+ imgs_lists.append(img_file)+ elif os.path.isdir(img_file):+ for single_file in os.listdir(img_file):+ file_path = os.path.join(img_file, single_file)+ if imghdr.what(file_path) in img_end:+ imgs_lists.append(file_path)+ if len(imgs_lists) == 0:+ raise FileNotFoundError("not found any img file in {}".format(img_file))+ return imgs_lists+++def check_and_read_gif(img_path):+ if os.path.basename(img_path)[-3:] in ['gif', 'GIF']:+ gif = cv2.VideoCapture(img_path)+ ret, frame = gif.read()+ if not ret:+ print("Cannot read {}. This gif image maybe corrupted.")+ return None, False+ if len(frame.shape) == 2 or frame.shape[-1] == 1:+ frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)+ imgvalue = frame[:, :, ::-1]+ return imgvalue, True+ return None, False+++class CTCLabelDecode(object):""" Convert between text-label and text-index """- def __init__(self,- character_dict_path=None,- character_type='ch',- use_space_char=False):- self.character_str = ""- assert character_dict_path is not None, "character_dict_path should not be None when character_type is ch"+ def __init__(self, character_dict_path):+ super(CTCLabelDecode, self).__init__()+ self.character_str = []+ assert character_dict_path is not None, "character_dict_path should not be None"with open(character_dict_path, "rb") as fin:lines = fin.readlines()for line in lines:line = line.decode('utf-8').strip("\n").strip("\r\n")- self.character_str += line- if use_space_char:- self.character_str += " "- dict_character = list(self.character_str)+ self.character_str.append(line)+ dict_character = self.character_str- self.character_type = character_typedict_character = self.add_special_char(dict_character)self.dict = {}for i, char in enumerate(dict_character):self.dict[char] = iself.character = dict_character+ def __call__(self, preds, label=None, *args, **kwargs):+ preds_idx = preds.argmax(axis=2)+ preds_prob = preds.max(axis=2)+ text = self.decode(preds_idx, preds_prob, is_remove_duplicate=True)+ if label is None:+ return text+ label = self.decode(label)+ return text, label+def add_special_char(self, dict_character):+ dict_character = ['blank'] + dict_characterreturn dict_character- def decode(self, text_index, text_prob=None, is_remove_duplicate=True):+ def get_ignored_tokens(self):+ return [0] # for ctc blank++ def decode(self, text_index, text_prob=None, is_remove_duplicate=False):""" convert text-index into text-label. """result_list = []ignored_tokens = self.get_ignored_tokens()@@ -63,62 +103,3 @@ class BaseRecLabelDecode(object):result_list.append((text, np.mean(conf_list)))return result_list- def get_ignored_tokens(self):- return [0] # for ctc blank---class CTCLabelDecode(BaseRecLabelDecode):- """ Convert between text-label and text-index """-- def __init__(self,- character_dict_path=None,- character_type='ch',- use_space_char=False,- **kwargs):- super(CTCLabelDecode, self).__init__(character_dict_path,- character_type, use_space_char)-- def __call__(self, preds, label=None, *args, **kwargs):- preds_idx = preds.argmax(axis=2)- preds_prob = preds.max(axis=2)- text = self.decode(preds_idx, preds_prob)- if label is None:- return text- label = self.decode(label, is_remove_duplicate=False)- return text, label-- def add_special_char(self, dict_character):- dict_character = ['blank'] + dict_character- return dict_character---def get_image_file_list(img_file):- imgs_lists = []- if img_file is None or not os.path.exists(img_file):- raise Exception("not found any img file in {}".format(img_file))-- img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'GIF'}- if os.path.isfile(img_file) and imghdr.what(img_file) in img_end:- imgs_lists.append(img_file)- elif os.path.isdir(img_file):- for single_file in os.listdir(img_file):- file_path = os.path.join(img_file, single_file)- if imghdr.what(file_path) in img_end:- imgs_lists.append(file_path)- if len(imgs_lists) == 0:- raise Exception("not found any img file in {}".format(img_file))- return imgs_lists---def check_and_read_gif(img_path):- if os.path.basename(img_path)[-3:] in ['gif', 'GIF']:- gif = cv2.VideoCapture(img_path)- ret, frame = gif.read()- if not ret:- print("Cannot read {}. This gif image maybe corrupted.")- return None, False- if len(frame.shape) == 2 or frame.shape[-1] == 1:- frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)- imgvalue = frame[:, :, ::-1]- return imgvalue, True- return None, False\ No newline at end of filediff --git a/python/ch_ppocr_server_v2_det/text_detect.py b/python/ch_ppocr_server_v2_det/text_detect.pyindex a37ad41..a342a8c 100755--- a/python/ch_ppocr_server_v2_det/text_detect.py+++ b/python/ch_ppocr_server_v2_det/text_detect.py@@ -135,10 +135,8 @@ class TextDetector(object):if __name__ == "__main__":parser = argparse.ArgumentParser()- parser.add_argument('--image_path', type=str, default=None,- help='image_path|image_dir')- parser.add_argument('--model_path', type=str, default=None,- help='model_path')+ parser.add_argument('--image_path', type=str, help='image_path|image_dir')+ parser.add_argument('--model_path', type=str, help='model_path')args = parser.parse_args()text_detector = TextDetector(args.model_path)diff --git a/python/ch_ppocr_server_v2_rec/text_recognize.py b/python/ch_ppocr_server_v2_rec/text_recognize.pyindex af7dbd8..5f1e799 100755--- a/python/ch_ppocr_server_v2_rec/text_recognize.py+++ b/python/ch_ppocr_server_v2_rec/text_recognize.py@@ -32,23 +32,19 @@ root_path = Path(__file__).parentclass TextRecognizer(object):def __init__(self, rec_model_path):self.rec_image_shape = [3, 32, 320]- self.character_type = 'ch'self.rec_batch_num = 6- self.rec_algorithm = 'CRNN'self.character_dict_path = str(root_path / 'ppocr_keys_v1.txt')- self.use_space_char = True- self.postprocess_op = CTCLabelDecode(self.character_dict_path,- self.character_type,- self.use_space_char)+ self.postprocess_op = CTCLabelDecode(self.character_dict_path)self.session = onnxruntime.InferenceSession(rec_model_path)def resize_norm_img(self, img, max_wh_ratio):img_channel, img_height, img_width = self.rec_image_shapeassert img_channel == img.shape[2]- if self.character_type == "ch":- img_width = int((32 * max_wh_ratio))- max_wh_ratio = 1++ img_width = int((32 * max_wh_ratio))+ max_wh_ratio = 1+h, w = img.shape[:2]ratio = w / float(h)if math.ceil(img_height * ratio) > img_width:@@ -128,10 +124,10 @@ class TextRecognizer(object):if __name__ == "__main__":parser = argparse.ArgumentParser()- parser.add_argument('--image_dir', type=str, help='image_dir|image_path')+ parser.add_argument('--image_path', type=str, help='image_dir|image_path')parser.add_argument('--model_path', type=str, help='rec_model_path')args = parser.parse_args()text_recognizer = TextRecognizer(args.model_path)- rec_res, predict_time = text_recognizer(args.image_dir)+ rec_res, predict_time = text_recognizer(args.image_path)print(f'θ―ε«η»ζ: {rec_res}\t cost: {predict_time}s')diff --git a/python/ch_ppocr_server_v2_rec/utils.py b/python/ch_ppocr_server_v2_rec/utils.pyindex 8836d71..0831c37 100755--- a/python/ch_ppocr_server_v2_rec/utils.py+++ b/python/ch_ppocr_server_v2_rec/utils.py@@ -9,35 +9,75 @@ import imghdrimport numpy as np-class BaseRecLabelDecode(object):+def get_image_file_list(img_file):+ imgs_lists = []+ if img_file is None or not os.path.exists(img_file):+ raise FileNotFoundError("not found any img file in {}".format(img_file))++ img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'GIF'}+ if os.path.isfile(img_file) and imghdr.what(img_file) in img_end:+ imgs_lists.append(img_file)+ elif os.path.isdir(img_file):+ for single_file in os.listdir(img_file):+ file_path = os.path.join(img_file, single_file)+ if imghdr.what(file_path) in img_end:+ imgs_lists.append(file_path)+ if len(imgs_lists) == 0:+ raise FileNotFoundError("not found any img file in {}".format(img_file))+ return imgs_lists+++def check_and_read_gif(img_path):+ if os.path.basename(img_path)[-3:] in ['gif', 'GIF']:+ gif = cv2.VideoCapture(img_path)+ ret, frame = gif.read()+ if not ret:+ print("Cannot read {}. This gif image maybe corrupted.")+ return None, False+ if len(frame.shape) == 2 or frame.shape[-1] == 1:+ frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)+ imgvalue = frame[:, :, ::-1]+ return imgvalue, True+ return None, False+++class CTCLabelDecode(object):""" Convert between text-label and text-index """- def __init__(self,- character_dict_path=None,- character_type='ch',- use_space_char=False):- self.character_str = ""- assert character_dict_path is not None, "character_dict_path should not be None when character_type is ch"+ def __init__(self, character_dict_path):+ super(CTCLabelDecode, self).__init__()+ self.character_str = []+ assert character_dict_path is not None, "character_dict_path should not be None"with open(character_dict_path, "rb") as fin:lines = fin.readlines()for line in lines:line = line.decode('utf-8').strip("\n").strip("\r\n")- self.character_str += line- if use_space_char:- self.character_str += " "- dict_character = list(self.character_str)+ self.character_str.append(line)+ dict_character = self.character_str- self.character_type = character_typedict_character = self.add_special_char(dict_character)self.dict = {}for i, char in enumerate(dict_character):self.dict[char] = iself.character = dict_character+ def __call__(self, preds, label=None, *args, **kwargs):+ preds_idx = preds.argmax(axis=2)+ preds_prob = preds.max(axis=2)+ text = self.decode(preds_idx, preds_prob, is_remove_duplicate=True)+ if label is None:+ return text+ label = self.decode(label)+ return text, label+def add_special_char(self, dict_character):+ dict_character = ['blank'] + dict_characterreturn dict_character- def decode(self, text_index, text_prob=None, is_remove_duplicate=True):+ def get_ignored_tokens(self):+ return [0] # for ctc blank++ def decode(self, text_index, text_prob=None, is_remove_duplicate=False):""" convert text-index into text-label. """result_list = []ignored_tokens = self.get_ignored_tokens()@@ -63,62 +103,3 @@ class BaseRecLabelDecode(object):result_list.append((text, np.mean(conf_list)))return result_list- def get_ignored_tokens(self):- return [0] # for ctc blank---class CTCLabelDecode(BaseRecLabelDecode):- """ Convert between text-label and text-index """-- def __init__(self,- character_dict_path=None,- character_type='ch',- use_space_char=False,- **kwargs):- super(CTCLabelDecode, self).__init__(character_dict_path,- character_type, use_space_char)-- def __call__(self, preds, label=None, *args, **kwargs):- preds_idx = preds.argmax(axis=2)- preds_prob = preds.max(axis=2)- text = self.decode(preds_idx, preds_prob)- if label is None:- return text- label = self.decode(label, is_remove_duplicate=False)- return text, label-- def add_special_char(self, dict_character):- dict_character = ['blank'] + dict_character- return dict_character---def get_image_file_list(img_file):- imgs_lists = []- if img_file is None or not os.path.exists(img_file):- raise Exception("not found any img file in {}".format(img_file))-- img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'GIF'}- if os.path.isfile(img_file) and imghdr.what(img_file) in img_end:- imgs_lists.append(img_file)- elif os.path.isdir(img_file):- for single_file in os.listdir(img_file):- file_path = os.path.join(img_file, single_file)- if imghdr.what(file_path) in img_end:- imgs_lists.append(file_path)- if len(imgs_lists) == 0:- raise Exception("not found any img file in {}".format(img_file))- return imgs_lists---def check_and_read_gif(img_path):- if os.path.basename(img_path)[-3:] in ['gif', 'GIF']:- gif = cv2.VideoCapture(img_path)- ret, frame = gif.read()- if not ret:- print("Cannot read {}. This gif image maybe corrupted.")- return None, False- if len(frame.shape) == 2 or frame.shape[-1] == 1:- frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)- imgvalue = frame[:, :, ::-1]- return imgvalue, True- return None, False\ No newline at end of filediff --git a/python/japan_ppocr_mobile_v2_rec/text_recognize.py b/python/japan_ppocr_mobile_v2_rec/text_recognize.pyindex 9836383..ec398b3 100644--- a/python/japan_ppocr_mobile_v2_rec/text_recognize.py+++ b/python/japan_ppocr_mobile_v2_rec/text_recognize.py@@ -32,23 +32,19 @@ root_path = Path(__file__).parentclass TextRecognizer(object):def __init__(self, rec_model_path):self.rec_image_shape = [3, 32, 320]- self.character_type = 'ch'self.rec_batch_num = 6- self.rec_algorithm = 'CRNN'self.character_dict_path = str(root_path / 'japan_dict.txt')- self.use_space_char = True- self.postprocess_op = CTCLabelDecode(self.character_dict_path,- self.character_type,- self.use_space_char)+ self.postprocess_op = CTCLabelDecode(self.character_dict_path)self.session = onnxruntime.InferenceSession(rec_model_path)def resize_norm_img(self, img, max_wh_ratio):img_channel, img_height, img_width = self.rec_image_shapeassert img_channel == img.shape[2]- if self.character_type == "ch":- img_width = int((32 * max_wh_ratio))- max_wh_ratio = 1++ img_width = int((32 * max_wh_ratio))+ max_wh_ratio = 1+h, w = img.shape[:2]ratio = w / float(h)if math.ceil(img_height * ratio) > img_width:@@ -127,10 +123,10 @@ class TextRecognizer(object):if __name__ == "__main__":parser = argparse.ArgumentParser()- parser.add_argument('--image_dir', type=str, help='image_dir|image_path')+ parser.add_argument('--image_path', type=str, help='image_dir|image_path')parser.add_argument('--model_path', type=str, help='rec_model_path')args = parser.parse_args()text_recognizer = TextRecognizer(args.model_path)- rec_res, predict_time = text_recognizer(args.image_dir)+ rec_res, predict_time = text_recognizer(args.image_path)print(f'θ―ε«η»ζ: {rec_res}\t cost: {predict_time}s')diff --git a/python/japan_ppocr_mobile_v2_rec/utils.py b/python/japan_ppocr_mobile_v2_rec/utils.pyindex 8836d71..d3b2c65 100644--- a/python/japan_ppocr_mobile_v2_rec/utils.py+++ b/python/japan_ppocr_mobile_v2_rec/utils.py@@ -1,7 +1,7 @@# !/usr/bin/env python# -*- encoding: utf-8 -*--# @File: PostProcess.py-# @Time: 2021/01/19 14:12:35+# @File: utils.py+# @Time: 2021/05/22 10:53:17# @Author: Maximport cv2import os@@ -9,35 +9,75 @@ import imghdrimport numpy as np-class BaseRecLabelDecode(object):+def get_image_file_list(img_file):+ imgs_lists = []+ if img_file is None or not os.path.exists(img_file):+ raise FileNotFoundError("not found any img file in {}".format(img_file))++ img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'GIF'}+ if os.path.isfile(img_file) and imghdr.what(img_file) in img_end:+ imgs_lists.append(img_file)+ elif os.path.isdir(img_file):+ for single_file in os.listdir(img_file):+ file_path = os.path.join(img_file, single_file)+ if imghdr.what(file_path) in img_end:+ imgs_lists.append(file_path)+ if len(imgs_lists) == 0:+ raise FileNotFoundError("not found any img file in {}".format(img_file))+ return imgs_lists+++def check_and_read_gif(img_path):+ if os.path.basename(img_path)[-3:] in ['gif', 'GIF']:+ gif = cv2.VideoCapture(img_path)+ ret, frame = gif.read()+ if not ret:+ print("Cannot read {}. This gif image maybe corrupted.")+ return None, False+ if len(frame.shape) == 2 or frame.shape[-1] == 1:+ frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)+ imgvalue = frame[:, :, ::-1]+ return imgvalue, True+ return None, False+++class CTCLabelDecode(object):""" Convert between text-label and text-index """- def __init__(self,- character_dict_path=None,- character_type='ch',- use_space_char=False):- self.character_str = ""- assert character_dict_path is not None, "character_dict_path should not be None when character_type is ch"+ def __init__(self, character_dict_path):+ super(CTCLabelDecode, self).__init__()+ self.character_str = []+ assert character_dict_path is not None, "character_dict_path should not be None"with open(character_dict_path, "rb") as fin:lines = fin.readlines()for line in lines:line = line.decode('utf-8').strip("\n").strip("\r\n")- self.character_str += line- if use_space_char:- self.character_str += " "- dict_character = list(self.character_str)+ self.character_str.append(line)+ dict_character = self.character_str- self.character_type = character_typedict_character = self.add_special_char(dict_character)self.dict = {}for i, char in enumerate(dict_character):self.dict[char] = iself.character = dict_character+ def __call__(self, preds, label=None, *args, **kwargs):+ preds_idx = preds.argmax(axis=2)+ preds_prob = preds.max(axis=2)+ text = self.decode(preds_idx, preds_prob, is_remove_duplicate=True)+ if label is None:+ return text+ label = self.decode(label)+ return text, label+def add_special_char(self, dict_character):+ dict_character = ['blank'] + dict_characterreturn dict_character- def decode(self, text_index, text_prob=None, is_remove_duplicate=True):+ def get_ignored_tokens(self):+ return [0] # for ctc blank++ def decode(self, text_index, text_prob=None, is_remove_duplicate=False):""" convert text-index into text-label. """result_list = []ignored_tokens = self.get_ignored_tokens()@@ -63,62 +103,3 @@ class BaseRecLabelDecode(object):result_list.append((text, np.mean(conf_list)))return result_list- def get_ignored_tokens(self):- return [0] # for ctc blank---class CTCLabelDecode(BaseRecLabelDecode):- """ Convert between text-label and text-index """-- def __init__(self,- character_dict_path=None,- character_type='ch',- use_space_char=False,- **kwargs):- super(CTCLabelDecode, self).__init__(character_dict_path,- character_type, use_space_char)-- def __call__(self, preds, label=None, *args, **kwargs):- preds_idx = preds.argmax(axis=2)- preds_prob = preds.max(axis=2)- text = self.decode(preds_idx, preds_prob)- if label is None:- return text- label = self.decode(label, is_remove_duplicate=False)- return text, label-- def add_special_char(self, dict_character):- dict_character = ['blank'] + dict_character- return dict_character---def get_image_file_list(img_file):- imgs_lists = []- if img_file is None or not os.path.exists(img_file):- raise Exception("not found any img file in {}".format(img_file))-- img_end = {'jpg', 'bmp', 'png', 'jpeg', 'rgb', 'tif', 'tiff', 'gif', 'GIF'}- if os.path.isfile(img_file) and imghdr.what(img_file) in img_end:- imgs_lists.append(img_file)- elif os.path.isdir(img_file):- for single_file in os.listdir(img_file):- file_path = os.path.join(img_file, single_file)- if imghdr.what(file_path) in img_end:- imgs_lists.append(file_path)- if len(imgs_lists) == 0:- raise Exception("not found any img file in {}".format(img_file))- return imgs_lists---def check_and_read_gif(img_path):- if os.path.basename(img_path)[-3:] in ['gif', 'GIF']:- gif = cv2.VideoCapture(img_path)- ret, frame = gif.read()- if not ret:- print("Cannot read {}. This gif image maybe corrupted.")- return None, False- if len(frame.shape) == 2 or frame.shape[-1] == 1:- frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)- imgvalue = frame[:, :, ::-1]- return imgvalue, True- return None, False\ No newline at end of filediff --git a/python/rapidOCR.sh b/python/rapidOCR.shindex 9682f3e..d0148f1 100644--- a/python/rapidOCR.sh+++ b/python/rapidOCR.sh@@ -1,4 +1,7 @@-python RapidOCR.py --use_server False \+#! /bin/bash+set -e errexit++python rapidOCR.py --use_server False \--det_model_path models/ch_ppocr_mobile_v2.0_det_infer.onnx \--cls_model_path models/ch_ppocr_mobile_v2.0_cls_infer.onnx \--rec_model_path models/ch_ppocr_mobile_v2.0_rec_infer.onnx \