Jelajahi Sumber

格式修改

liweiquan 11 bulan lalu
induk
melakukan
fdbe690bcf
3 mengubah file dengan 20 tambahan dan 19 penghapusan
  1. 5 4
      cores/check_table.py
  2. 7 6
      cores/post_decorators.py
  3. 8 9
      server.py

+ 5 - 4
cores/check_table.py

@@ -23,7 +23,6 @@ class Table:
     #         print(r)
     #     return res
 
-
     def get_tr(self):
         # str = self.get_body()
         str = self.html
@@ -73,7 +72,7 @@ class Table:
         str = ''
         for tr in self.html_arr:
             for cell in tr:
-                str+=cell
+                str += cell
         return str
 
     def check_html(self):
@@ -83,8 +82,10 @@ class Table:
         print(self.html)
         print(self.html_arr)
         print(self.empty)
-        if (self.empty > 4 and self.empty > self.total // 4) or ('项目' in html_str and '每份' in html_str and '营养素参考值' in html_str and np.max([len(a) for a in self.html_arr])<3):
+        if (self.empty > 4 and self.empty > self.total // 4) or (
+                '项目' in html_str and '每份' in html_str and '营养素参考值' in html_str and np.max(
+                [len(a) for a in self.html_arr]) < 3):
             print('识别效果不佳,改变图片颜色!')
             self.change_green2white()
             return 1
-        return 0
+        return 0

+ 7 - 6
cores/post_decorators.py

@@ -71,7 +71,7 @@ def rule4_decorator(f, *args, **kwargs):
     predict_line = args[1]
     predict_line = f(*args, **kwargs)
     try:
-        if '项目' in predict_line[1] and predict_line[0]=='':
+        if '项目' in predict_line[1] and predict_line[0] == '':
             predict_line[0] = '项目'
             predict_line[1] = predict_line[1].replace('项目', '')
     except IndexError as e:
@@ -87,10 +87,11 @@ def rule5_decorator(f, *args, **kwargs):
     predict_line = args[1]
     predict_line = f(*args, **kwargs)
     try:
-        if '项目' in predict_line[0] and '营养素参考值' in predict_line[1] and len(predict_line[1])>7 and predict_line[2] == '':
+        if '项目' in predict_line[0] and '营养素参考值' in predict_line[1] and len(predict_line[1]) > 7 and \
+                predict_line[2] == '':
             predict_line[2] = '营养素参考值'
-            if len(predict_line[1].split('营养素参考值'))>1:
-                predict_line[2] = predict_line[2]+predict_line[1].split('营养素参考值')[1]
+            if len(predict_line[1].split('营养素参考值')) > 1:
+                predict_line[2] = predict_line[2] + predict_line[1].split('营养素参考值')[1]
             predict_line[1] = predict_line[1].split('营养素参考值')[0]
     except IndexError as e:
         print('rule5_decorator', e)
@@ -113,7 +114,7 @@ def rule6_decorator(f, *args, **kwargs):
                 predict_line[1] = predict_line[2].split('营养素参考值')[0]
                 r = predict_line[2].split('营养素参考值')
                 if len(r) == 2:
-                    predict_line[2] = '营养素参考值'+r[1]
+                    predict_line[2] = '营养素参考值' + r[1]
     except IndexError as e:
         print('rule6_decorator', e)
-    return predict_line
+    return predict_line

+ 8 - 9
server.py

@@ -20,7 +20,6 @@ import paddleclas
 from cores.post_hander import *
 from cores.check_table import *
 
-
 format_print()
 
 # 初始化APP
@@ -35,7 +34,6 @@ app.add_middleware(
     allow_headers=["*"],
 )
 
-
 table_engine_lock = threading.Lock()
 
 table_engine = PPStructure(layout=False,
@@ -43,15 +41,16 @@ table_engine = PPStructure(layout=False,
                            use_gpu=True,
                            show_log=True,
                            use_angle_cls=True,
-                        #    det_model_dir="models/det/det_table_v2",
-                        #    det_model_dir="models/det/det_table_v3",
-                        #    rec_model_dir="models/rec/rec_table_v1",
+                           #    det_model_dir="models/det/det_table_v2",
+                           #    det_model_dir="models/det/det_table_v3",
+                           #    rec_model_dir="models/rec/rec_table_v1",
                            table_model_dir="models/table/SLANet_911")
 
-
 cls_lock = threading.Lock()
 
 cls_model = paddleclas.PaddleClas(model_name="text_image_orientation")
+
+
 # # 普通表格
 # table_engine = PPStructure(layout=False,
 #                            table=True,
@@ -102,7 +101,6 @@ def cal_html_to_chs(html):
     return len(rec_res)
 
 
-
 def predict_cls(image, conf=0.8):
     try:
         cls_lock.acquire()
@@ -146,6 +144,7 @@ def get_zero_degree_image(img):
             continue
     return img
 
+
 def table_res(im, ROTATE=-1):
     im = im.copy()
     # cv2.imwrite('before-rotate.jpg', im)
@@ -160,6 +159,7 @@ def table_res(im, ROTATE=-1):
     html = res[0]['res']['html']
     return res, html
 
+
 class TableInfo(BaseModel):
     image: str
     det: str
@@ -176,11 +176,10 @@ def table(image: TableInfo):
     img = base64_to_np(image.image)
     res, html = table_res(img)
     # print(html)
-    table = Table(html,img)
+    table = Table(html, img)
     if table.check_html():
         res, html = table_res(table.img)
 
-
     if html:
         post_hander = PostHandler(html)
         # print(post_hander.format_predict_html)