|
@@ -1,17 +1,16 @@
|
|
|
from flask import Flask, render_template, request
|
|
|
from utils.util import *
|
|
|
from utils.conf import MAX_CONTENT_LENGTH
|
|
|
+import logging
|
|
|
import numpy as np
|
|
|
import cv2
|
|
|
from paddleocr import PaddleOCR
|
|
|
|
|
|
-# from paddleocr import PaddleOCR
|
|
|
-# from utils import Args
|
|
|
-# from paddleocr.tools.infer.predict_system import TextSystem
|
|
|
-#
|
|
|
app = Flask(__name__)
|
|
|
-# 待优化为 TextSystem
|
|
|
-eng1 = PaddleOCR(
|
|
|
+app.config["JSON_AS_ASCII"] = False
|
|
|
+
|
|
|
+logging.getLogger("ppocr").setLevel(logging.WARN)
|
|
|
+engine = PaddleOCR(
|
|
|
use_gpu=False,
|
|
|
enable_mkldnn=True,
|
|
|
det_model_dir="models/det/",
|
|
@@ -22,16 +21,6 @@ eng1 = PaddleOCR(
|
|
|
)
|
|
|
|
|
|
|
|
|
-# args = Args(
|
|
|
-# use_gpu=False,
|
|
|
-# enable_mkldnn=True,
|
|
|
-# det_model_dir="models/det/",
|
|
|
-# rec_model_dir="models/rec/",
|
|
|
-# )
|
|
|
-# eng2 = TextSystem(args)
|
|
|
-# warmup
|
|
|
-
|
|
|
-
|
|
|
@app.route("/")
|
|
|
def index():
|
|
|
return render_template("index.html")
|
|
@@ -56,7 +45,7 @@ def ocr_raw():
|
|
|
|
|
|
# 内容识别
|
|
|
array = cv2.imdecode(np.fromstring(content, np.uint8), 1) # noqa
|
|
|
- ocr_res = eng1.ocr(array)[0]
|
|
|
+ ocr_res = engine.ocr(array)[0]
|
|
|
res = [{"pos": it[0], "word": it[1][0], "rate": it[1][1]} for it in ocr_res]
|
|
|
return Response(data=res)
|
|
|
|
|
@@ -80,7 +69,7 @@ def ocr_filter():
|
|
|
|
|
|
# 内容识别
|
|
|
array = cv2.imdecode(np.fromstring(content, np.uint8), 1) # noqa
|
|
|
- ocr_res = eng1.ocr(array)[0]
|
|
|
+ ocr_res = engine.ocr(array)[0]
|
|
|
|
|
|
# 过滤出想要的数据
|
|
|
res = [it[1][0] for it in ocr_res]
|
|
@@ -108,7 +97,7 @@ def ocr_html():
|
|
|
|
|
|
# 内容识别
|
|
|
array = cv2.imdecode(np.fromstring(content, np.uint8), 1) # noqa
|
|
|
- ocr_res = eng1.ocr(array)[0]
|
|
|
+ ocr_res = engine.ocr(array)[0]
|
|
|
res = [{"pos": it[0], "word": it[1][0], "rate": it[1][1]} for it in ocr_res]
|
|
|
|
|
|
# 画图
|
|
@@ -119,27 +108,3 @@ def ocr_html():
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
app.run()
|
|
|
-
|
|
|
-"""
|
|
|
-step:
|
|
|
- pip install PaddlePaddle-GPU==2.4.2 PaddleOCR
|
|
|
- pip install PaddleHub
|
|
|
- hub install chinese_ocr_db_crnn_server
|
|
|
-
|
|
|
-
|
|
|
-python E:/Project/Python/PaddleOCR/venv/Lib/site-packages/paddleocr/tools/infer/predict_system.py
|
|
|
- --image_dir="C:/Users/huimv/Pictures/Saved Pictures/"
|
|
|
- --det_model_dir="D:/BaiduNetdisk/module/aiengine/model/ocr/ch_pp-ocrv3_det_infer/"
|
|
|
- --rec_model_dir="D:/BaiduNetdisk/module/aiengine/model/ocr/ch_pp-ocrv3_rec_infer/"
|
|
|
- --cls_model_dir="D:/BaiduNetdisk/module/aiengine/model/ocr/ch_ppocr_mobile_v2.0_cls_infer/"
|
|
|
- --use_angle_cls=True --use_space_char=True --use_gpu=False
|
|
|
-
|
|
|
-python tools/infer/predict_system.py
|
|
|
- --image_dir="E:/Project/Python/PaddleOCR/static/pic2.png"
|
|
|
- --det_model_dir="E:/Project/Python/PaddleOCR/models/det/"
|
|
|
- --rec_model_dir="E:/Project/Python/PaddleOCR/models/rec/"
|
|
|
-
|
|
|
-
|
|
|
-deploy:
|
|
|
- python -m pip install PaddlePaddle==2.4.2 PaddleOCR -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
-"""
|