Преглед изворни кода

idc ocr v2.1: 2 engines only

Tinger пре 2 година
родитељ
комит
24c8f65c64

+ 2 - 1
.gitignore

@@ -3,4 +3,5 @@ venv
 .idea
 static/images/*
 
-test.py
+test.py
+hmOCR

+ 1 - 1
app.py

@@ -25,7 +25,7 @@ def index():
 
 @app.route("/favicon.ico")
 def icon():
-    with open("static/favicon.png", "rb") as f:
+    with open("static/html/favicon.png", "rb") as f:
         img = f.read()
         f.close()
     return Response(img, mimetype="image/x-png")

static/common.svg → static/html/common.svg


static/favicon.png → static/html/favicon.png


static/identity.svg → static/html/identity.svg


static/more.svg → static/html/more.svg


Разлика између датотеке није приказан због своје велике величине
+ 6623 - 0
static/ppocr/ppocr_keys_v1.txt


static/simfang.ttf → static/ppocr/simfang.ttf


+ 3 - 3
templates/navigate.html

@@ -55,15 +55,15 @@
 <h1>HuiMv OCR Navigator</h1>
 <div class="demos">
     <div rel="/com" class="demo link">
-        <img src="/static/common.svg" alt="common">
+        <img src="/static/html/common.svg" alt="common">
         <span>通用内容识别模型,可识别任意图片中的所有文字内容,对图片要求不高。</span>
     </div>
     <div rel="/idc" class="demo link">
-        <img src="/static/identity.svg" alt="identity">
+        <img src="/static/html/identity.svg" alt="identity">
         <span>中国大陆身份证内容识别,主要识别:姓名、性别、民族、身份证号、地址、有效日期。</span>
     </div>
     <div class="demo">
-        <img src="/static/more.svg" alt="more">
+        <img src="/static/html/more.svg" alt="more">
         <span>更多内容,有待开发...<br>更多内容,有待开发...<br>更多内容,有待开发...</span>
     </div>
 </div>

+ 6 - 6
utils/util.py

@@ -16,15 +16,15 @@ __all__ = [
 __StrBase = "qwertyuioplkjhgfdsazxcvbnm1234567890ZXCVBNMLKJHGFDSAQWERTYUIOP"
 __StrBaseLen = len(__StrBase) - 1
 __AcceptExtNames = ["jpg", "jpeg", "bmp", "png", "rgb", "tif", "tiff", "gif", "pdf"]
+__EngineNum = 2
 __Engines = [PaddleOCR(
     use_gpu=False,
     enable_mkldnn=True,
     det_model_dir="models/det/",
     rec_model_dir="models/rec/",
     cls_model_dir="models/cls/",
-    use_angle_cls=True,
-    use_space_char=True
-) for _ in range(4)]
+    use_angle_cls=True
+) for _ in range(__EngineNum)]
 
 
 class Args:
@@ -97,11 +97,11 @@ def Response(message: "str" = None, data=None):
 
 
 def _rec(img, which: "int" = 0) -> "tuple[list, tuple]":
-    return __Engines[which % 4].ocr(img)[0], img.shape
+    return __Engines[which % __EngineNum].ocr(img)[0], img.shape
 
 
 def rec_multi(images: "list[np.ndarray]") -> "list[tuple]":  # list[_rec]
-    pool = ThreadPoolExecutor(4)
+    pool = ThreadPoolExecutor(__EngineNum)
     tasks = [pool.submit(_rec, one, i) for i, one in enumerate(images)]
 
     return [task.result() for task in tasks]
@@ -121,7 +121,7 @@ def draw_img(shape: "tuple", data: "list[dict]", path: "str", drop: "float" = 0.
         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"], font_path="static/simfang.ttf")
+        text = draw_box_txt_fine((shape[1], shape[0]), one["pos"], one["word"], font_path="static/ppocr/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