未验证 提交 f18ddffa 编写于 作者: 文幕地方's avatar 文幕地方 提交者: GitHub

update inference of PP-OCRv2 to paddlecv (#5587)

* add install of paddleclas

* update inference with paddlecv
上级 71792d0e
...@@ -3,10 +3,8 @@ import base64 ...@@ -3,10 +3,8 @@ import base64
from io import BytesIO from io import BytesIO
from PIL import Image from PIL import Image
import paddleocr from paddlecv import PaddleCV
from paddleocr import PaddleOCR, draw_ocr ocr = PaddleCV(task_name="PP-OCRv2")
ocr = PaddleOCR(ocr_version='PP-OCRv2', use_angle_cls=True, lang="ch")
def image_to_base64(image): def image_to_base64(image):
...@@ -20,20 +18,16 @@ def image_to_base64(image): ...@@ -20,20 +18,16 @@ def image_to_base64(image):
# UGC: Define the inference fn() for your models # UGC: Define the inference fn() for your models
def model_inference(image): def model_inference(image):
result = ocr.ocr(image, cls=True) result = ocr(image)[0]
# 显示结果
if paddleocr.__version__ >= "2.6.0.2":
result = result[0]
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=None, scores=None)
im_show = Image.fromarray(im_show)
im_show = Image.open('output/tmp.jpg')
res = [] res = []
for i in range(len(boxes)): for i in range(len(result['dt_polys'])):
res.append(dict(boxes=boxes[i], txt=txts[i], score=scores[i])) res.append(
dict(
boxes=result['dt_polys'][i],
txt=result['rec_text'][i],
score=result['rec_score'][i]))
json_out = {"base64": image_to_base64(im_show), "result": res} json_out = {"base64": image_to_base64(im_show), "result": res}
return im_show, json_out return im_show, json_out
......
...@@ -3,10 +3,8 @@ import base64 ...@@ -3,10 +3,8 @@ import base64
from io import BytesIO from io import BytesIO
from PIL import Image from PIL import Image
import paddleocr from paddlecv import PaddleCV
from paddleocr import PaddleOCR, draw_ocr ocr = PaddleCV(task_name="PP-OCRv3")
ocr = PaddleOCR(use_angle_cls=True, lang="ch")
def image_to_base64(image): def image_to_base64(image):
...@@ -20,20 +18,16 @@ def image_to_base64(image): ...@@ -20,20 +18,16 @@ def image_to_base64(image):
# UGC: Define the inference fn() for your models # UGC: Define the inference fn() for your models
def model_inference(image): def model_inference(image):
result = ocr.ocr(image, cls=True) result = ocr(image)[0]
# 显示结果
if paddleocr.__version__ >= "2.6.0.2":
result = result[0]
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=None, scores=None)
im_show = Image.fromarray(im_show)
im_show = Image.open('output/tmp.jpg')
res = [] res = []
for i in range(len(boxes)): for i in range(len(result['dt_polys'])):
res.append(dict(boxes=boxes[i], txt=txts[i], score=scores[i])) res.append(
dict(
boxes=result['dt_polys'][i],
txt=result['rec_text'][i],
score=result['rec_score'][i]))
json_out = {"base64": image_to_base64(im_show), "result": res} json_out = {"base64": image_to_base64(im_show), "result": res}
return im_show, json_out return im_show, json_out
......
...@@ -3,9 +3,8 @@ import base64 ...@@ -3,9 +3,8 @@ import base64
from io import BytesIO from io import BytesIO
from PIL import Image from PIL import Image
from paddleocr import PPStructure from paddlecv import PaddleCV
table_engine = PaddleCV(task_name="PP-StructureV2-table")
table_engine = PPStructure(layout=False, show_log=True)
def image_to_base64(image): def image_to_base64(image):
...@@ -19,8 +18,8 @@ def image_to_base64(image): ...@@ -19,8 +18,8 @@ def image_to_base64(image):
# UGC: Define the inference fn() for your models # UGC: Define the inference fn() for your models
def model_inference(image): def model_inference(image):
result = table_engine(image) result = table_engine(image)[0]
res = result[0]['res']['html'] res = result['html']
json_out = {"result": res} json_out = {"result": res}
return res, json_out return res, json_out
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册