From 6c19d15a571a4cbc83461b749e8056e99992af6e Mon Sep 17 00:00:00 2001 From: WenmuZhou Date: Mon, 2 Aug 2021 17:22:31 +0800 Subject: [PATCH] save figure --- paddleocr.py | 6 ++++-- ppstructure/README.md | 3 ++- ppstructure/README_ch.md | 3 ++- ppstructure/predict_system.py | 12 ++++++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/paddleocr.py b/paddleocr.py index d14f7b8b0..914109ba5 100644 --- a/paddleocr.py +++ b/paddleocr.py @@ -369,6 +369,8 @@ def main(): logger.info(line) elif args.type == 'structure': result = engine(img_path) - for item in result: - logger.info(item['res']) save_structure_res(result, args.output, img_name) + + for item in result: + item.pop('img') + logger.info(item['res']) diff --git a/ppstructure/README.md b/ppstructure/README.md index 00e8ba8f2..2833bd076 100644 --- a/ppstructure/README.md +++ b/ppstructure/README.md @@ -38,6 +38,7 @@ result = table_engine(img) save_structure_res(result, save_folder,os.path.basename(img_path).split('.')[0]) for line in result: + line.pop('img') print(line) from PIL import Image @@ -80,7 +81,7 @@ The description of each field in dict is as follows Most of the parameters are consistent with the paddleocr whl package, see [doc of whl](../doc/doc_en/whl_en.md) -After running, each image will have a directory with the same name under the directory specified in the output field. Each table in the picture will be stored as an excel, and the excel file name will be the coordinates of the table in the image. +After running, each image will have a directory with the same name under the directory specified in the output field. Each table in the picture will be stored as an excel and figure area will be cropped and saved, the excel and image file name will be the coordinates of the table in the image. ## 2. PPStructure Pipeline diff --git a/ppstructure/README_ch.md b/ppstructure/README_ch.md index 296b730e2..4f961cfc3 100644 --- a/ppstructure/README_ch.md +++ b/ppstructure/README_ch.md @@ -39,6 +39,7 @@ result = table_engine(img) save_structure_res(result, save_folder,os.path.basename(img_path).split('.')[0]) for line in result: + line.pop('img') print(line) from PIL import Image @@ -82,7 +83,7 @@ dict 里各个字段说明如下 大部分参数和paddleocr whl包保持一致,见 [whl包文档](../doc/doc_ch/whl.md) -运行完成后,每张图片会在`output`字段指定的目录下有一个同名目录,图片里的每个表格会存储为一个excel,excel文件名为表格在图片里的坐标。 +运行完成后,每张图片会在`output`字段指定的目录下有一个同名目录,图片里的每个表格会存储为一个excel,图片区域会被裁剪之后保存下来,excel文件和图片名名为表格在图片里的坐标。 ## 2. PPStructure Pipeline diff --git a/ppstructure/predict_system.py b/ppstructure/predict_system.py index 1bae89737..503ed1269 100644 --- a/ppstructure/predict_system.py +++ b/ppstructure/predict_system.py @@ -65,17 +65,17 @@ class OCRSystem(object): filter_boxes = [x + [x1, y1] for x in filter_boxes] filter_boxes = [x.reshape(-1).tolist() for x in filter_boxes] # remove style char - style_token = ['','','','','','','','', - '','','','','',''] + style_token = ['', '', '', '', '', '', '', '', + '', '', '', '', '', ''] filter_rec_res_tmp = [] for rec_res in filter_rec_res: rec_str, rec_conf = rec_res for token in style_token: if token in rec_str: rec_str = rec_str.replace(token, '') - filter_rec_res_tmp.append((rec_str,rec_conf)) + filter_rec_res_tmp.append((rec_str, rec_conf)) res = (filter_boxes, filter_rec_res_tmp) - res_list.append({'type': region.type, 'bbox': [x1, y1, x2, y2], 'res': res}) + res_list.append({'type': region.type, 'bbox': [x1, y1, x2, y2], 'img': roi_img, 'res': res}) return res_list @@ -88,6 +88,10 @@ def save_structure_res(res, save_folder, img_name): if region['type'] == 'Table': excel_path = os.path.join(excel_save_folder, '{}.xlsx'.format(region['bbox'])) to_excel(region['res'], excel_path) + if region['type'] == 'Figure': + roi_img = region['img'] + img_path = os.path.join(excel_save_folder, '{}.jpg'.format(region['bbox'])) + cv2.imwrite(img_path, roi_img) else: for box, rec_res in zip(region['res'][0], region['res'][1]): f.write('{}\t{}\n'.format(np.array(box).reshape(-1).tolist(), rec_res))