save figure

pull/3497/head
WenmuZhou 2021-08-02 17:22:31 +08:00
parent 6a121aa7cf
commit 6c19d15a57
4 changed files with 16 additions and 8 deletions

View File

@ -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'])

View File

@ -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

View File

@ -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`字段指定的目录下有一个同名目录图片里的每个表格会存储为一个excelexcel文件名为表格在图片里的坐标。
运行完成后,每张图片会在`output`字段指定的目录下有一个同名目录图片里的每个表格会存储为一个excel图片区域会被裁剪之后保存下来,excel文件和图片名名为表格在图片里的坐标。
## 2. PPStructure Pipeline

View File

@ -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 = ['<strike>','<strike>','<sup>','</sub>','<b>','</b>','<sub>','</sup>',
'<overline>','</overline>','<underline>','</underline>','<i>','</i>']
style_token = ['<strike>', '<strike>', '<sup>', '</sub>', '<b>', '</b>', '<sub>', '</sup>',
'<overline>', '</overline>', '<underline>', '</underline>', '<i>', '</i>']
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))