diff --git a/paddleocr.py b/paddleocr.py index d14f7b8b098ce2da8f387bb526bb450432eb4ae9..914109ba586e12f0bb70b1714aa2adc99e65c09a 100644 --- a/paddleocr.py +++ b/paddleocr.py @@ -369,6 +369,8 @@ def main(): logger.info(line) elif args.type == 'structure': result = engine(img_path) + save_structure_res(result, args.output, img_name) + for item in result: + item.pop('img') logger.info(item['res']) - save_structure_res(result, args.output, img_name) diff --git a/ppstructure/README.md b/ppstructure/README.md index 00e8ba8f2aa8f1c53a70e5c502852c0f028aaeef..2833bd0767d9fd89a57119dc557117861e5e9f58 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 296b730e29f3b5a1b6029f02c5c9875b9127709b..4f961cfc3f4e5686583191467c9cb313cd5c3a52 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 1bae89737e9511bc275212cf16ab1519621f5b66..503ed1269e42678961d9e5ae94b9ae855d2c944d 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))