|
@@ -1,6 +1,7 @@
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
import json
|
|
|
from base64 import b64decode
|
|
|
+import base64
|
|
|
|
|
|
import cv2
|
|
|
import numpy as np
|
|
@@ -17,6 +18,7 @@ from sx_utils.sx_log import *
|
|
|
import paddleclas
|
|
|
|
|
|
from cores.post_hander import *
|
|
|
+from cores.check_table import *
|
|
|
|
|
|
|
|
|
format_print()
|
|
@@ -111,17 +113,20 @@ def predict_cls(image, conf=0.8):
|
|
|
score = res[0]['scores'][0]
|
|
|
label_name = res[0]['label_names'][0]
|
|
|
print(f"score: {score}, label_name: {label_name}")
|
|
|
+ # print(conf)
|
|
|
if score > conf:
|
|
|
return int(label_name)
|
|
|
return -1
|
|
|
|
|
|
|
|
|
def rotate_to_zero(image, current_degree):
|
|
|
+ # cv2.imwrite('1.jpg', image)
|
|
|
current_degree = current_degree // 90
|
|
|
if current_degree == 0:
|
|
|
return image
|
|
|
to_rotate = (4 - current_degree) - 1
|
|
|
image = cv2.rotate(image, to_rotate)
|
|
|
+ # cv2.imwrite('2.jpg', image)
|
|
|
return image
|
|
|
|
|
|
|
|
@@ -143,9 +148,10 @@ def get_zero_degree_image(img):
|
|
|
|
|
|
def table_res(im, ROTATE=-1):
|
|
|
im = im.copy()
|
|
|
+ # cv2.imwrite('before-rotate.jpg', im)
|
|
|
# 获取正向图片
|
|
|
img = get_zero_degree_image(im)
|
|
|
- # cv2.imwrite('1.jpg', img)
|
|
|
+ # cv2.imwrite('after-rotate.jpg', img)
|
|
|
try:
|
|
|
table_engine_lock.acquire()
|
|
|
res = table_engine(img)
|
|
@@ -169,9 +175,15 @@ def ping():
|
|
|
def table(image: TableInfo):
|
|
|
img = base64_to_np(image.image)
|
|
|
res, html = table_res(img)
|
|
|
+ # print(html)
|
|
|
+ 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)
|
|
|
return {'html': post_hander.format_predict_html}
|
|
|
else:
|
|
|
raise Exception('无法识别')
|