98ec226f by 周伟奇

fix auth from

1 parent 7e35e5ba
......@@ -18,7 +18,7 @@ print(res) # {'label': '营业执照', 'confidence': 0.988462}
from authorization_from import retriever_individuals, retriever_companies
# 个人授权书
res = retriever_companies.get_target_fields(go_res, signature_res)
res = retriever_individuals.get_target_fields(go_res, signature_res)
print(res)
# {'words_result':
# {'姓名': {'words': 'xx', 'score': 1, 'location': {'left': 105, 'top': 277, 'width': 60, 'height': 28}},
......@@ -27,7 +27,7 @@ print(res)
# }
# 公司授权书
# res = retriever_individuals.get_target_fields(go_res, signature_res)
# res = retriever_companies.get_target_fields(go_res, signature_res)
# print(res)
# {'words_result': {
......
......@@ -4,8 +4,8 @@ TARGET_FIELD_INDIVIDUALS = {
'个人身份证件号码': [('个人身份证件号码', 'top1', {})],
},
'value': {
'姓名': ('under', {'left_padding': 1, 'right_padding': 1}, ''),
'个人身份证件号码': ('under', {'left_padding': 0.5, 'right_padding': 0.5}, '')
'姓名': ('under', {'left_padding': 1, 'right_padding': 1, 'scope': 2}, ''),
'个人身份证件号码': ('under', {'left_padding': 0.5, 'right_padding': 0.5, 'scope': 2}, '')
},
'signature': {
'签字': {'signature', }
......@@ -19,17 +19,17 @@ TARGET_FIELD_COMPANIES = {
],
'经销商代码-宝马中国': [
('经销商代码', 'top1', {}),
('宝马中国', 'right', {'top_padding': 1.5, 'bottom_padding': 0})
('宝马中国', 'right', {'top_padding': 1.5, 'bottom_padding': 0, 'scope': 2})
],
'管理人员姓名-总经理': [
('管理人员姓名', 'top1', {}),
('总经理', 'right', {'top_padding': 1, 'bottom_padding': 0})
('总经理', 'right', {'top_padding': 1, 'bottom_padding': 0, 'scope': 2})
],
},
'value': {
'经销商名称': ('right', {'top_padding': 1, 'bottom_padding': 1}, ''),
'经销商代码-宝马中国': ('right', {'top_padding': 0.5, 'bottom_padding': 0.5}, ''),
'管理人员姓名-总经理': ('right', {'top_padding': 0.5, 'bottom_padding': 0.5}, '')
'经销商名称': ('right', {'top_padding': 1, 'bottom_padding': 1, 'scope': 4}, ''),
'经销商代码-宝马中国': ('right', {'top_padding': 0.5, 'bottom_padding': 0.5, 'scope': 3, 'value_type': 'int'}, ''),
'管理人员姓名-总经理': ('right', {'top_padding': 0.5, 'bottom_padding': 0.5, 'scope': 5}, '')
},
'signature': {
'公司公章': {'circle', },
......
......@@ -8,6 +8,11 @@ class Retriever:
self.signature_have_not_str = '无'
self.target_fields = target_fields
self.key_text_set = self.get_key_text_set(target_fields)
self.replace_map = {
'int': {
'(': '0'
}
}
def get_key_text_set(self, target_fields):
# 关键词集合
......@@ -24,58 +29,78 @@ class Retriever:
return coordinates_list[0]
@staticmethod
def key_right(coordinates_list, key_coordinates, top_padding, bottom_padding):
def key_right(coordinates_list, key_coordinates, top_padding, bottom_padding, scope):
# 关键词查找方向:右侧
if len(coordinates_list) == 1:
return coordinates_list[0]
height = key_coordinates[-1] - key_coordinates[1]
y_min = key_coordinates[1] - (top_padding * height)
y_max = key_coordinates[-1] + (bottom_padding * height)
x = key_coordinates[2]
x_min = None
width = key_coordinates[2] - key_coordinates[0]
x_min = key_coordinates[2]
x_max = key_coordinates[2] + (width * scope)
x_min_find = None
key_coordinates = None
for x0, y0, x1, y1 in coordinates_list:
if y0 > y_min and y1 < y_max and x0 > x:
if x_min is None or x0 < x_min:
x_min = x0
cent_x = x0 + ((x1 - x0) / 2)
cent_y = y0 + ((y1 - y0) / 2)
if x_min < cent_x < x_max and y_min < cent_y < y_max:
if x_min_find is None or x0 < x_min_find:
x_min_find = x0
key_coordinates = (x0, y0, x1, y1)
return key_coordinates
@staticmethod
def value_right(go_res, key_coordinates, top_padding, bottom_padding):
def value_right(self, go_res, key_coordinates, top_padding, bottom_padding, scope, value_type=None):
# 字段值查找方向:右侧
height = key_coordinates[-1] - key_coordinates[1]
y_min = key_coordinates[1] - (top_padding * height)
y_max = key_coordinates[-1] + (bottom_padding * height)
x = key_coordinates[2]
x_min = None
width = key_coordinates[2] - key_coordinates[0]
x_min = key_coordinates[2]
x_max = key_coordinates[2] + (width * scope)
x_min_find = None
value = None
coordinates = None
for (x0, y0, _, _, x1, y1, _, _), text in go_res.values():
if y0 > y_min and y1 < y_max and x0 > x:
if x_min is None or x0 < x_min:
x_min = x0
cent_x = x0 + ((x1 - x0) / 2)
cent_y = y0 + ((y1 - y0) / 2)
if x_min < cent_x < x_max and y_min < cent_y < y_max:
if x_min_find is None or x0 < x_min_find:
if len(text.strip()) > 0:
x_min_find = x0
value = text
coordinates = (x0, y0, x1, y1)
if isinstance(value_type, str) and value_type in self.replace_map and isinstance(value, str):
new_value = value.translate(str.maketrans(self.replace_map.get(value_type, {})))
return new_value, coordinates
return value, coordinates
@staticmethod
def value_under(go_res, key_coordinates, left_padding, right_padding):
def value_under(go_res, key_coordinates, left_padding, right_padding, scope, value_type=None):
# 字段值查找方向:下方
width = key_coordinates[2] - key_coordinates[0]
x_min = key_coordinates[0] - (width * left_padding)
x_max = key_coordinates[2] + (width * right_padding)
y = key_coordinates[-1]
y_min = None
height = key_coordinates[-1] - key_coordinates[1]
y_min = key_coordinates[-1]
y_max = key_coordinates[-1] + (height * scope)
y_min_find = None
value = None
coordinates = None
for (x0, y0, _, _, x1, y1, _, _), text in go_res.values():
if x0 > x_min and x1 < x_max and y0 > y:
if y_min is None or y0 < y_min:
y_min = y0
cent_x = x0 + ((x1 - x0)/2)
cent_y = y0 + ((y1 - y0)/2)
if x_min < cent_x < x_max and y_min < cent_y < y_max:
if y_min_find is None or y0 < y_min_find:
if len(text.strip()) > 0:
y_min_find = y0
value = text
coordinates = (x0, y0, x1, y1)
return value, coordinates
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!