Commit aef53ac1 by 杨林龙

保存全量识别阶段

1 parent 9de9d798
...@@ -5,30 +5,42 @@ import shutil ...@@ -5,30 +5,42 @@ import shutil
import cv2 import cv2
from paddleocr import PPStructure, draw_structure_result, save_structure_res from paddleocr import PPStructure, draw_structure_result, save_structure_res
if os.path.exists("result03.jpg"):
os.remove("result03.jpg")
table_engine = PPStructure( table_engine = PPStructure(
mode="structure", mode="structure",
# mode="kie",
layout=True, layout=True,
ocr=True, ocr=True,
table=True, table=True,
show_log=True, show_log=True,
# invert=True, invert=True,
use_angle_cls=True, use_angle_cls=True,
# det_model_dir="ch_ppocr_server_v4.0_det_infer/", # det_model_dir="ch_ppocr_server_v4.0_det_infer/",
det_model_dir="ch_ppocr_server_v4.0_det_infer/", det_model_dir="ch_ppocr_server_v4.0_det_infer/",
cls_model_dir="ch_ppocr_mobile_v4.0_cls_infer/", cls_model_dir="ch_ppocr_mobile_v4.0_cls_infer/",
rec_model_dir="ch_ppocr_server_v4.0_rec_infer/", rec_model_dir="ch_ppocr_server_v4.0_rec_infer/",
re_model_dir="re_vi_layoutxlm_xfund_infer", re_model_dir="re_vi_layoutxlm_xfund_infer",
# layout_model_dir='' table_model_dir="ch_ppstructure_mobile_v2.0_SLANet_infer",
ser_model_dir="ser_vi_layoutxlm_xfund_infer",
use_tensorrt=True, use_tensorrt=True,
use_dilation=True, use_dilation=True,
image_orientation=True, # image_orientation=True,
recovery=True, recovery=True,
table_max_len=488 * 5,
e2e_limit_side_len=768 * 2,
det_limit_side_len=736 * 2,
) )
# table_engine = PPStructure(show_log=True, image_orientation=True)
# table_engine = PPStructure(show_log=True, image_orientation=False)
save_folder = "./output" save_folder = "./output"
# img_path = './table/1.png' # img_path = './table/1.png'
img_path = "./ocr_invoice/ocr-vin-0007.jpg" img_path = "./ocr_invoice/ocr-vin-0007.jpg"
img = cv2.imread(img_path) img = cv2.imread(img_path)
img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
result = table_engine(img) result = table_engine(img)
# 删除文件 # 删除文件
print(save_folder + "/" + os.path.basename(img_path).split(".")[0]) print(save_folder + "/" + os.path.basename(img_path).split(".")[0])
...@@ -46,5 +58,4 @@ font_path = "doc/fonts/simfang.ttf" # PaddleOCR下提供字体包 ...@@ -46,5 +58,4 @@ font_path = "doc/fonts/simfang.ttf" # PaddleOCR下提供字体包
image = Image.open(img_path).convert("RGB") image = Image.open(img_path).convert("RGB")
im_show = draw_structure_result(image, result, font_path=font_path) im_show = draw_structure_result(image, result, font_path=font_path)
im_show = Image.fromarray(im_show) im_show = Image.fromarray(im_show)
os.remove("result03.jpg")
im_show.save("result03.jpg") im_show.save("result03.jpg")
...@@ -5,6 +5,9 @@ from paddleocr import PaddleOCR, draw_ocr ...@@ -5,6 +5,9 @@ from paddleocr import PaddleOCR, draw_ocr
from PIL import Image from PIL import Image
from pprint import pprint from pprint import pprint
if os.path.exists("result04.jpg"):
os.remove("result04.jpg")
# load model # load model
# Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改 lang参数进行切换 # Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改 lang参数进行切换
# lang参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan` # lang参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`
...@@ -52,23 +55,21 @@ for line in result: ...@@ -52,23 +55,21 @@ for line in result:
image = Image.open(img_path).convert("RGB") image = Image.open(img_path).convert("RGB")
boxes = [line[0] for line in result[0]] boxes = [line[0] for line in result[0]]
txts = [line[1][0] for line in result[0]] txts = [line[1][0] for line in result[0]]
# all_context = "\n".join(txts) all_context = "\n".join(txts)
all_context = "".join(txts) # all_context = "".join(txts)
# print("\n".join(txts)) # print("\n".join(txts))
print(all_context) print(all_context)
scores = [line[1][1] for line in result[0]] scores = [line[1][1] for line in result[0]]
im_show = draw_ocr(image, boxes, txts, scores, font_path="./simfang.ttf") im_show = draw_ocr(image, boxes, txts, scores, font_path="./simfang.ttf")
im_show = Image.fromarray(im_show) im_show = Image.fromarray(im_show)
# im_show.show() # im_show.show()
if os.path.exists("result04.jpg"):
os.remove("result04.jpg")
im_show.save("result04.jpg") im_show.save("result04.jpg")
from paddlenlp import Taskflow from paddlenlp import Taskflow
schema = ["车辆类型", "账号", "机关及代码", "备注"] schema = ["车辆类型", "账号", "机关及代码", "备注"]
ie = Taskflow("information_extraction",schema=schema) ie = Taskflow("information_extraction", schema=schema)
ie.set_schema(schema) ie.set_schema(schema)
one = ie(all_context)
print("one===") print("one===")
pprint(one) pprint(ie(all_context))
print("two===")
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!