def img_word_translate(img_path): ocr = PaddleOCR(use_angle_cls=True, lang="ch") result = ocr.ocr(img_path, cls=True) image = Image.open(img_path).convert('RGB') boxes = [line[0] for line in result] txts = [line[1][0] for line in result] scores = [line[1][1] for line in result] im_show = draw_ocr(image, boxes, txts, scores, font_path='/doc/simfang.ttf') im_show = Image.fromarray(im_show) n = 0 stR = "" for line in result: # print(line[1]) n += 1 texts = line[1][0] if re.findall('[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]', texts): stR = stR + str(texts) else: stR = stR + str(texts) + "," # print(texts) print(stR) translate(stR, "en", "zh-CN") im_show.show() return stR
def ocr_once(): ocr = PaddleOCR(use_angle_cls=True, lang="ch") img_path = '/home/jiantang/桌面/tmp/certification/认证合一/归档/道路运输证/c1_001.png' image = cv2.imread(img_path) result = ocr.ocr(image, cls=True) # 保存框框结果 boxes = [line[0] for line in result] txts = [line[1][0] for line in result] scores = [line[1][1] for line in result] for i in range(len(boxes)): pts = np.array(boxes[i], np.int32) pts = pts.reshape((-1, 1, 2)) cv2.polylines(image, [pts], True, (0, 255, 255)) cv2.imwrite('tmp_img.png', image) # 保存文字结果 img = np.zeros((image.shape[0], image.shape[1], 3), np.uint8) for i in range(len(boxes)): pts = np.array(boxes[i], np.int32) pts = pts.reshape((-1, 1, 2)) cv2.polylines(img, [pts], True, (0, 255, 255)) img = cv2ImgAddText(img, txts[i], int(boxes[i][0][0] - 1), int(boxes[i][0][1] - 1), (0, 255, 255), 20) cv2.imwrite('tmp_txt.png', img) cv2.imshow('line', img) cv2.waitKey()
def ocr_once(path): ocr = PaddleOCR(use_angle_cls=True, lang="ch") img = cv2.imread(path) result = ocr.ocr(img, cls=True) # print(type(result)) print(result) return check_c1(result)
def __init__(self, args): self.args = args self.max_seq_length = args.max_seq_length # init ser token and model tokenizer_class, base_model_class, model_class = MODELS[ args.ser_model_type] self.tokenizer = tokenizer_class.from_pretrained( args.model_name_or_path) self.model = model_class.from_pretrained(args.model_name_or_path) self.model.eval() # init ocr_engine from paddleocr import PaddleOCR self.ocr_engine = PaddleOCR( rec_model_dir=args.rec_model_dir, det_model_dir=args.det_model_dir, use_angle_cls=False, show_log=False) # init dict label2id_map, self.id2label_map = get_bio_label_maps( args.label_map_path) self.label2id_map_for_draw = dict() for key in label2id_map: if key.startswith("I-"): self.label2id_map_for_draw[key] = label2id_map["B" + key[1:]] else: self.label2id_map_for_draw[key] = label2id_map[key]
def one_pred(img_path): ocr = PaddleOCR(use_angle_cls=True, lang="ch") result = ocr.ocr(img_path, cls=True) image = Image.open(img_path).convert('RGB') boxes = [line[0] for line in result] txts = [line[1][0] for line in result] scores = [line[1][1] for line in result] im_show = draw_ocr(image, boxes, txts, scores, font_path='/doc/simfang.ttf') im_show = Image.fromarray(im_show) n = 0 stR = "" for line in result: #print(line[1]) n += 1 texts = line[1][0] stR = stR + "," + str(texts) #print(texts) print(stR) im_show.show() return stR
def GetText(path=None,result_pic=False): """ 文字识别 :param path:图片路径 :return: """ if not path: path = "F:/git/wxbot/dm/pic/222.png" # ocr = PaddleOCR(use_gpu=False,det_model_dir="./inference/ch_det_mv3_db/",rec_model_dir="./inference/ch_det_mv3_db/") # need to run only once to download and load model into memory ocr = PaddleOCR(gpu=False, det_model_dir="./inference/ch_det_r50_vd_db", rec_model_dir="./inference/ch_rec_r34_vd_crnn_infer") # need to run only once to download and load model into memory result = ocr.ocr(path) txts = [line[1][0] for line in result] # 展示图片 if result_pic: image = Image.open(path).convert('RGB') boxes = [line[0] for line in result] scores = [line[1][1] for line in result] im_show = draw_ocr(image, boxes, txts, scores) im_show = Image.fromarray(im_show) TMP_FILE = os.path.join(conf.TMP_PATH, "result.png") im_show.save(TMP_FILE) # print(txts) return txts
def __init__( self, remove_numeric_tables: bool = False, valid_languages: Optional[List[str]] = ["eng"], ): """ :param remove_numeric_tables: This option uses heuristics to remove numeric rows from the tables. The tabular structures in documents might be noise for the reader model if it does not have table parsing capability for finding answers. However, tables may also have long strings that could possible candidate for searching answers. The rows containing strings are thus retained in this option. :param valid_languages: validate languages from a list of languages specified here (https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html) This option can be used to add test for encoding errors. If the extracted text is not one of the valid languages, then it might likely be encoding error resulting in garbled text. Run the following line of code to check available language packs: # List of available languages print(pytesseract.get_languages(config='')) """ # save init parameters to enable export of component config as YAML self.set_config(remove_numeric_tables=remove_numeric_tables, valid_languages=valid_languages) self.recognize = PaddleOCR(use_angle_cls=True, lang='ch') super().__init__(remove_numeric_tables=remove_numeric_tables, valid_languages=valid_languages)
def convert_from_url(img_url): ocr = PaddleOCR(use_angle_cls=True, lang="ch") response = requests.get(img_url) image = np.array(Image.open(BytesIO(response.content))) result = ocr.ocr(image, cls=True) text = [line[1][0] for line in result] return " ".join(text)
def one_pred(img_path): ocr = PaddleOCR(use_angle_cls=True, lang="ch") result = ocr.ocr(img_path, cls=False) # print(result) n = 0 stR = "" phone = "" #电话 shopName = "" #店铺名 describe = "" #描述 otherinfo = "没有其他信息" print("+++", result) for line in result: n += 1 texts = line[1][0] if texts == "": continue if len(texts) < 2: continue r = test.pre(texts) if len(texts) < 3: continue if r == "商铺名": shopName = shopName + texts continue s = ms.pre(texts) if s == "描述": describe = describe + texts continue stR = stR + str(line[1][0]) + ":" + str(line[1][1]) + "\n" phones = texts.split("1") # print("++",phone) for i in phones: # print(i) if re.match(r'^[1-9]\d{9}$', i): a = "1" + i # print(a) phone = phone + ";" + a else: phone = " 图片中没有电话信息" phone = phone[1:] print("****", shopName, phone, describe, otherinfo) #return im_show.show() image = Image.open(img_path).convert('RGB') boxes = [line[0] for line in result] txts = [line[1][0] for line in result] scores = [line[1][1] for line in result] im_show = draw_ocr(image, boxes, txts, scores, font_path='/doc/simfang.ttf') im_show = Image.fromarray(im_show) # im_show.show() # im_show.save是保存识别后的图片 fanhui_img = 'result.jpg' im_show.save(fanhui_img) return shopName, phone, describe, otherinfo, fanhui_img
def __init__(self): self.ocr_model = PaddleOCR( use_angle_cls=True, # det='ch_ppocr_server_v1.1_det', det_model_dir='./pretrained_models/ch_ppocr_server_v2.0_det_infer', # rec='ch_ppocr_server_v1.1_rec', rec_model_dir='./pretrained_models/ch_ppocr_server_v2.0_rec_infer', cls='ch_ppocr_mobile_v1.1_cls')
def init(): ocr = PaddleOCR( use_angle_cls=True, lang="ch" ) # need to run only once to download and load model into memory img_path = './data/3.jpg' result = ocr.ocr(img_path, cls=True) for line in result: print(line)
def __init__(self): self.model = PaddleOCR(use_angle_cls=True, lang="ch") with open(os.path.join(os.getcwd(), "confs/certificate.yaml"), "r", encoding='UTF-8') as f: self.config = yaml.load(f, Loader=yaml.FullLoader) self.tmp_result = {} self.pos_dict = {} # To tell client witch certificate the image is. self.face_feature = [] self.reset()
def ocr_run(): global ocr_init ocr = PaddleOCR(use_angle_cls=True, use_gpu=True, use_tensorrt=False, gpu_mem=3000, det_max_side_len=960, rec_batch_num=2) cnt = 0 last_result = [] while not b_exit: try: frame = ocr_queue.get(block=True, timeout=0.1) except: continue print('ocr got one frame ....') t0 = time.time() result = ocr.ocr(frame, cls=True) t1 = time.time() #try: # speech_que.put_nowait(result) #except: # pass if len(result) < 1: continue try: if last_result: likehood = samelike(last_result, result) if likehood >= 0.6: # and len(last_result) == len(result): Speech.Block_Speech_text("请翻页") last_result = result continue last_result = result except: traceback.print_exc() pass if 1: text_lst = [] for line in result: text = line[1][0] text_lst.append(text) print(line) for text in text_lst: Speech.Block_Speech_text(text) cnt += 1 if cnt % 1 == 0: print("frame cnt [%d] ocr detect delay = %.1fms" % (cnt, (t1 - t0) * 1000))
def convertText2(self, img): ocr = PaddleOCR( ) # need to run only once to download and load model into memory result = ocr.ocr( img) # return a list with coordinates, content and accuracy index = 0 done = False for line in result: if done: break [corList, (txt, _)] = line [[_, y1], [x2, _], [_, _], [_, y4]] = corList if '期货品种' in txt: self.findContent2(index, y1, y4, x2, result, '期货品种') elif '现货头寸' in txt: self.findContent2(index, y1, y4, x2, result, '现货头寸') elif '期货头寸' in txt: self.findContent2(index, y1, y4, x2, result, '期货头寸') elif '现货数量' in txt: self.findContent2(index, y1, y4, x2, result, '现货数量') elif '手' in txt: self.findContent2(index, y1, y4, x2, result, '合约数量') elif '计划套保' in txt: [corListPrev, (txtP, _)] = result[index - 1] [corListAft, (txtA, _)] = result[index + 1] [[_, yp1], _, _, _] = corListPrev [[_, ya1], _, _, _] = corListAft if abs(yp1 - y1) < abs(ya1 - y1): self.textDict['hedgeRatio'] = txtP else: self.textDict['hedgeRatio'] = txtA elif '保证金规模' in txt: self.findContent2(index, y1, y4, x2, result, '保证金规模') elif txt == '最大亏损限额': self.findContent2(index, y1, y4, x2, result, '最大亏损') elif txt == '行情分析': self.get_multi_lines(index, result, '行情分析') elif txt == '持仓预案': self.get_multi_lines(index, result, '持仓预案') elif txt == '平仓预案': self.get_multi_lines(index, result, '平仓预案') elif '止盈位' in txt: self.get_multi_lines(index, result, '止盈') elif '止损位' in txt: self.get_multi_lines(index, result, '止损') elif '备注' in txt: self.get_multi_lines(index, result, '备注') done = True index += 1
def demo_use(): # Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改lang参数进行切换,参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。 ocr = PaddleOCR(use_angle_cls=True, lang="en", use_gpu=False) # 输入待识别图片路径 img_path = "C:/Users/FH/Desktop/ocrtupianjieya/icpr_mtwi_task1/test_line_image_transfer/line_101415.jpg" # img_path = "C:/Users/FH/Desktop/line_101415_angel.jpg" # img_path = "../pillow_toolkits/line_100031_higher_gray.jpg" # 输出结果保存路径 result = ocr.ocr(img_path, det=False, cls=True) print(result)
def one_pred(img_path): ocr = PaddleOCR(use_angle_cls=True, lang="ch") result = ocr.ocr(img_path, cls=True) image = Image.open(img_path).convert('RGB') boxes = [line[0] for line in result] txts = [line[1][0] for line in result] scores = [line[1][1] for line in result] im_show = draw_ocr(image, boxes, txts, scores, font_path='/doc/simfang.ttf') im_show = Image.fromarray(im_show) im_show.show()
def ocr_preprocess(img_dir): ocr = PaddleOCR(use_angle_cls=True, lang="ch", use_gpu=True) ocr_reses = [] img_names = sorted( os.listdir(img_dir), key=lambda x: int(x.split("_")[1].split(".")[0])) for img_name in img_names: img_path = os.path.join(img_dir, img_name) parsing_res = ocr.ocr(img_path, cls=True) ocr_res = [] for para in parsing_res: ocr_res.append({"text": para[1][0], "bbox": para[0]}) ocr_reses.append((img_name, ocr_res)) return ocr_reses
def create_ocr(self, lang, use_gpu=False): try: ocr = PaddleOCR(lang=lang, use_gpu=use_gpu or self.use_gpu, use_angle_cls=True, gpu_mem=200) except AssertionError: print('创建OCR实例失败: lang={}'.format(lang)) else: self.func[lang] = ocr
def __init__(self): # self.ocr = PaddleOCR(use_angle_cls=True) self.ocr = { # "en":PaddleOCR(lang="en"), "ch": PaddleOCR(lang="ch") } self.drop_scores = 0.5
def __init__(self): dynaconf_config_ocr = settings.get('ocr', {}) det_model_dir = os.getcwd() + dynaconf_config_ocr.det_model_dir rec_model_dir = os.getcwd() + dynaconf_config_ocr.rec_model_dir rec_char_dict_path = os.getcwd( ) + dynaconf_config_ocr.rec_char_dict_path cls_model_dir = os.getcwd() + dynaconf_config_ocr.cls_model_dir self.min_angle = dynaconf_config_ocr.min_angle self.max_angle = dynaconf_config_ocr.max_angle self.angle_step = dynaconf_config_ocr.angle_step self.text_score_thresh = dynaconf_config_ocr.text_score_thresh self.ocr = PaddleOCR( det_model_dir=det_model_dir, rec_model_dir=rec_model_dir, rec_char_dict_path=rec_char_dict_path, cls_model_dir=cls_model_dir, use_angle_cls=dynaconf_config_ocr.angle_switch, use_gpu=False, )
def detect_OCR(self, img): # Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改lang参数进行切换 # 参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。 ocr = PaddleOCR(use_angle_cls=True, use_gpu=False, lang="ch", use_space_char=True,det_db_unclip_ratio=2.0) # det_db_unclip_ratio=2.5这是参数定义位置,这个参数是检测后处理时控制文本框大小的,默认2.0,可以尝试改成2.5或者更大,反之,如果觉得文本框不够紧凑,也可以把该参数调小。 need to run only once to download and load model into memory img_path = img result = ocr.ocr(img_path,cls=False) for line in result: print(line) # 显示结果 from PIL import Image image = Image.open(img_path).convert('RGB') boxes = [line[0] for line in result] txts = [line[1][0] for line in result] scores = [line[1][1] for line in result] im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/simfang.ttf') im_show = Image.fromarray(im_show) im_show.save('result.jpg') return boxes, txts
def demo_use2(): ocr = PaddleOCR(use_angle_cls=True, lang="ch") file_dir = "C:/Users/FH/Desktop/ocrtupianjieya/icpr_mtwi_task1/test_line_image_transfer" file_names = os.listdir(file_dir) reader = open( "C:/Users/FH/Desktop/ocrtupianjieya/icpr_mtwi_task1/result_transfer.txt", 'r', encoding='utf8') already_files = [i.strip().split(" ")[0] for i in reader.readlines()] reader.close() writer = open( "C:/Users/FH/Desktop/ocrtupianjieya/icpr_mtwi_task1/result_transfer.txt", 'a+', encoding='utf8') import time begin_time = time.time() count = 0 for index, file_name in enumerate(file_names): if file_name in already_files: continue count += 1 out = "" try: file_path = os.path.join(file_dir, file_name) result = ocr.ocr(file_path, det=False, cls=False) if result: out = result[0][0] writer.write(file_name + " " + out + "\n") if count <= 10: print(result) if (index + 1) % 500 == 0: print("当前已处理{}条数据,目前处理平均速度为{}条/s".format( index + 1, count / (time.time() - begin_time))) writer.flush() # if index == 5000: # break except Exception as e: print("============error===========") print(e) print(file_name) writer.write(file_name + " " + out + "\n") writer.close()
def text_detection(input_file='../data/input/30800.jpg', output_file='../data/output', show=False, method='google', paddle_model=None): ''' :param method: google or paddle :param paddle_model: the preload paddle model for paddle ocr ''' start = time.clock() name = input_file.split('/')[-1][:-4] ocr_root = pjoin(output_file, 'ocr') img = cv2.imread(input_file) if method == 'google': print('*** Detect Text through Google OCR ***') ocr_result = ocr.ocr_detection_google(input_file) texts = text_cvt_orc_format(ocr_result) texts = merge_intersected_texts(texts) texts = text_filter_noise(texts) texts = text_sentences_recognition(texts) elif method == 'paddle': # The import of the paddle ocr can be separate to the beginning of the program if you decide to use this method from paddleocr import PaddleOCR print('*** Detect Text through Paddle OCR ***') if paddle_model is None: paddle_model = PaddleOCR(use_angle_cls=True, lang="ch") result = paddle_model.ocr(input_file, cls=True) texts = text_cvt_orc_format_paddle(result) else: raise ValueError('Method has to be "google" or "paddle"') visualize_texts(img, texts, shown_resize_height=800, show=show, write_path=pjoin(ocr_root, name + '.png')) save_detection_json(pjoin(ocr_root, name + '.json'), texts, img.shape) print("[Text Detection Completed in %.3f s] Input: %s Output: %s" % (time.clock() - start, input_file, pjoin(ocr_root, name + '.json')))
def ocr_once(): # Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改lang参数进行切换 # 参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。 ocr = PaddleOCR( use_angle_cls=True, lang="ch" ) # need to run only once to download and load model into memory img_path = 'test/3.jpg' img = cv2.imread(img_path) start = time.time() result = ocr.ocr(img, cls=True) print(result) print(time.time() - start) # 显示结果 from PIL import Image image = Image.open(img_path).convert('RGB') boxes = [line[0] for line in result] txts = [line[1][0] for line in result] scores = [line[1][1] for line in result] im_show = draw_ocr(image, boxes, txts, scores, font_path='simfang.ttf') im_show = Image.fromarray(im_show) im_show.save('result/result3.jpg')
def convertText1(self, img): ocr = PaddleOCR( ) # need to run only once to download and load model into memory result = ocr.ocr( img) # return a list with coordinates, content and accuracy index = 0 done = False for line in result: if done: break [corList, (txt, _)] = line [[x1, y1], [x2, y2], [x3, y3], [x4, y4]] = corList if txt == '委托主体名称': [corListPrev, (txtP, _)] = result[index - 1] [corListAft, (txtA, _)] = result[index + 1] [[_, yp1], _, _, _] = corListPrev [[_, ya1], _, _, _] = corListAft if abs(yp1 - y1) < abs(ya1 - y1): self.textDict['entrustSubject'] = txtP else: self.textDict['entrustSubject'] = txtA elif txt == '操作主体名称': [corListPrev, (txtP, _)] = result[index - 1] [corListAft, (txtA, _)] = result[index + 1] [[_, yp1], _, _, _] = corListPrev [[_, ya1], _, _, _] = corListAft if abs(yp1 - y1) < abs(ya1 - y1): self.textDict['operatorName'] = txtP else: self.textDict['operatorName'] = txtA elif '现货品种' in txt: self.findContent1(index, y1, y4, x2, result, '现货品种') elif '开仓价格' in txt: self.findContent1(index, y1, y4, x2, result, '开仓价格') done = True index += 1
class Vehicle_License_Plate_Recognition(nn.Layer): def __init__(self): super(Vehicle_License_Plate_Recognition, self).__init__() self.vlpr = PaddleOCR( det_model_dir=os.path.join(self.directory, 'det_vlpr'), rec_model_dir=os.path.join(self.directory, 'ch_ppocr_server_v2.0_rec_infer')) @staticmethod def base64_to_cv2(b64str): data = base64.b64decode(b64str.encode('utf8')) data = np.frombuffer(data, np.uint8) data = cv2.imdecode(data, cv2.IMREAD_COLOR) return data def plate_recognition(self, images=None): assert isinstance(images, (list, str, np.ndarray)) results = [] if isinstance(images, list): for item in images: for bbox, text in self.vlpr.ocr(item): results.append({'license': text[0], 'bbox': bbox}) elif isinstance(images, (str, np.ndarray)): for bbox, text in self.vlpr.ocr(images): results.append({'license': text[0], 'bbox': bbox}) return results @serving def serving_method(self, images): if isinstance(images, list): images_decode = [self.base64_to_cv2(image) for image in images] elif isinstance(images, str): images_decode = self.base64_to_cv2(images) return self.plate_recognition(images_decode)
def ocr(): upload = request.files.get('upload') lang = request.forms.get('lang') print(lang) global current_lang global ocr if current_lang!=lang: current_lang=lang ocr = PaddleOCR(lang=current_lang) name, ext = os.path.splitext(upload.filename) print(ext.lower()) if ext.lower() not in ('.png','.jpg','.jpeg'): return "File extension not allowed." timestamp=str(int(time.time()*1000)) savedName=timestamp+ext save_path = "./uploaded/" if not os.path.exists(save_path): os.makedirs(save_path) file_path = "{path}/{file}".format(path=save_path, file=savedName) if os.path.exists(file_path)==True: os.remove(file_path) upload.save(file_path) ret = {} result = ocr.ocr(file_path) text_lines=[] for line in result: text_line={} index=0 for coord in line[0]: text_line["x"+str(index)]=int(coord[0]) text_line["y"+str(index)]=int(coord[1]) index=index+1 text_line["text"]=line[1][0] text_lines.append(text_line) os.remove(file_path) ret["text_lines"]=text_lines return ret
def detect(image): # PATH_IMG_IN = './in' # filename = os.path.join(PATH_IMG_IN, '1.png') # filename = 'FSRCNNp2x2.jpg' # image = cv2.imread("picture2.jpg") # cv2.imshow("a", image) image1 = copy.deepcopy(image[0:int(image.shape[0]/2), 0:int(image.shape[1]/2), :]) # print(image.shape) # cv2.imshow("b", image1) # cv2.waitKey() ocr = PaddleOCR() # need to run only once to download and load model into memory start = time.perf_counter() result = ocr.ocr(image1, rec=True) # 第一个坐标表示的是第几个识别的字,第二个表示的识别的字中的是字的坐标还是还是字的内容或者置信度,第三个坐标表示的是四个坐 # 标中的第几个坐标,第四个坐标是是一个具体的坐标的x或者y # print(result) end = time.perf_counter() print('检测文字区域 耗时{}'.format(end - start)) # 每个矩形,从左上角顺时针排列 for rect1 in result: if 'XODTC' in rect1[1][0]: # print(rect1[1][0]) return rect1[1][0]
def __init__(self, hwnd): self.hwnd = hwnd self.get_parent_size() currfiletpath = Path(os.path.abspath(__file__)) self.currtpath = currfiletpath.parent self.mous = PyMouse() self.ditu_size = { "jianye": (287, 142), "donghaiwan": (119, 119), "changancheng": (548, 277), "jiangnanyewai": (159, 119), "aolaiguo": (222, 150), "huaguoshan": (159, 119), "beijuluzhou": (226, 169), "changshoujiaowai": (191, 167) } self.yunbiao_par = ["牛魔王", "观音姐姐", "镇元大仙", "孙婆婆", "地藏王"] self.padocr = PaddleOCR(use_angle_cls=True, lang="ch") # 调用百度的识别文字 APP_ID = '25963522' API_KEY = 'RIOFdoDKGXfhHr2uLYVmUG8w' SECRET_KEY = 'vnWA7s1WfWsrPwEvkgkiVI7MMxNTjFvw' self.client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
def gen_ocr_data(cls, imfile=None, **kwargs): """" 支持调用PaddleOCR进行预识别 """ from paddleocr import PaddleOCR ppocr = PaddleOCR.get_paddleocr() data = cls.gen_data(imfile, **kwargs) lines = ppocr.ocr(str(imfile)) for line in lines: pts, [text, score] = line pts = [[int(p[0]), int(p[1])] for p in pts] # 转整数 sp = cls.gen_shape({ 'text': text, 'score': round(float(score), 4) }, pts) data['shapes'].append(sp) return data