Kaynağa Gözat

Merge branch 'master' of http://192.168.1.7:3000/Tinger/OCR into gpu

Tinger 2 yıl önce
ebeveyn
işleme
334d97f371
7 değiştirilmiş dosya ile 21 ekleme ve 49 silme
  1. 4 0
      .gitignore
  2. 1 1
      Dockerfile
  3. 7 4
      Readme.md
  4. 8 43
      app.py
  5. 0 0
      gunicorn.conf.py
  6. 0 0
      static/images/init.pic
  7. 1 1
      utils/util.py

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+__pycache__
+venv
+.idea
+static/images/*

+ 1 - 1
Dockerfile

@@ -12,4 +12,4 @@ RUN pip install --no-cache-dir --upgrade pip -i $tuna && \
  apt update && apt install -y ffmpeg libsm6 libxext6 --no-install-recommends && \
  apt-get clean && rm -rf /var/lib/apt/lists/*
 
-CMD ["gunicorn", "app:app", "-c", "gunicorn.conf"]
+CMD ["gunicorn", "app:app"]

+ 7 - 4
Readme.md

@@ -2,9 +2,10 @@
 
 ---
 
-**$host: http://139.9.167.178:5051**
+**$host: http://139.9.167.178:5050**
 
-**接口说明:[ApiPost-OCR接口说明](https://console-docs.apipost.cn/preview/2b4cea51f80eaed2/33c12de1392ea998)**
+**接口说明:[内网](http://192.168.1.6:10393/shareDoc?issue=b0f1852e84df1504ccf22ea3d170a0b9) 、
+[外网](https://console-docs.apipost.cn/preview/4c3153799dc211ad/be9b128db3073b6e)**
 
 ---
 
@@ -17,11 +18,13 @@
   + 参数列表:
     + picture: 待识别的图片文件
   + 返回数据:JSON
-  + 详见:[ApiPost 接口说明1](https://console-docs.apipost.cn/preview/29f73aa84047b12a/b294d4eccd3ec68e)
+  + 详见接口说明:[内网](http://192.168.1.6:10393/shareDoc?issue=b575bc0bb3eed8ad21ea192ac75f9df2) 、
+    [外网](https://console-docs.apipost.cn/preview/29f73aa84047b12a/b294d4eccd3ec68e)
 
 + $host/ocr-filter/
   + 请求方法:POST
   + 参数列表:
     + picture: 待识别的图片文件
   + 返回数据:JSON
-  + 详见:[ApiPost 接口说明2](https://console-docs.apipost.cn/preview/91517399fb42f789/47a77024dd17b335)
+  + 详见接口说明:[内网](http://192.168.1.6:10393/shareDoc?issue=67be17c547640a13c30db5a3fcff1dea) 、
+    [外网](https://console-docs.apipost.cn/preview/91517399fb42f789/47a77024dd17b335)

+ 8 - 43
app.py

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

gunicorn.conf → gunicorn.conf.py


+ 0 - 0
static/images/init.pic


+ 1 - 1
utils/util.py

@@ -89,7 +89,7 @@ def draw_img(shape: "tuple", data: "list[dict]", drop: "float" = 0.5):
         if one["rate"] < drop:
             continue
         color = (randint(0, 255), randint(0, 255), randint(0, 255))
-        text = draw_box_txt_fine((shape[1], shape[0]), one["pos"], one["word"])
+        text = draw_box_txt_fine((shape[1], shape[0]), one["pos"], one["word"], font_path="static/simfang.ttf")
         pts = np.array(one["pos"], np.int32).reshape((-1, 1, 2))
         cv2.polylines(text, [pts], True, color, 1)  # noqa
         img = cv2.bitwise_and(img, text)  # noqa