fix dealername4
Showing
2 changed files
with
15 additions
and
11 deletions
... | @@ -7,7 +7,7 @@ TARGET_FIELD_INDIVIDUALS = { | ... | @@ -7,7 +7,7 @@ TARGET_FIELD_INDIVIDUALS = { |
7 | 'value': { | 7 | 'value': { |
8 | '姓名': ('under', {'left_padding': 1, 'right_padding': 1, 'scope': 2}, ''), | 8 | '姓名': ('under', {'left_padding': 1, 'right_padding': 1, 'scope': 2}, ''), |
9 | '个人身份证件号码': ('under', {'left_padding': 0.5, 'right_padding': 0.5, 'scope': 2}, ''), | 9 | '个人身份证件号码': ('under', {'left_padding': 0.5, 'right_padding': 0.5, 'scope': 2}, ''), |
10 | '经销商名称': ('under', {'left_padding': 0.1, 'right_padding': 0.1, 'scope': 2}, '') | 10 | '经销商名称': ('under', {'left_padding': 0.1, 'right_padding': 0.5, 'scope': 2, 'append': True}, '') |
11 | }, | 11 | }, |
12 | 'signature': { | 12 | 'signature': { |
13 | '签字': {'signature', } | 13 | '签字': {'signature', } | ... | ... |
... | @@ -92,7 +92,7 @@ class Retriever: | ... | @@ -92,7 +92,7 @@ class Retriever: |
92 | return value, coordinates | 92 | return value, coordinates |
93 | 93 | ||
94 | @staticmethod | 94 | @staticmethod |
95 | def value_under(go_res, key_coordinates, left_padding, right_padding, scope, value_type=None): | 95 | def value_under(go_res, key_coordinates, left_padding, right_padding, scope, value_type=None, append=False): |
96 | # 字段值查找方向:下方 | 96 | # 字段值查找方向:下方 |
97 | width = key_coordinates[2] - key_coordinates[0] | 97 | width = key_coordinates[2] - key_coordinates[0] |
98 | x_min = key_coordinates[0] - (width * left_padding) | 98 | x_min = key_coordinates[0] - (width * left_padding) |
... | @@ -102,19 +102,23 @@ class Retriever: | ... | @@ -102,19 +102,23 @@ class Retriever: |
102 | y_min = key_coordinates[-1] | 102 | y_min = key_coordinates[-1] |
103 | y_max = key_coordinates[-1] + (height * scope) | 103 | y_max = key_coordinates[-1] + (height * scope) |
104 | 104 | ||
105 | y_min_find = None | 105 | find_list = [] |
106 | value = None | ||
107 | coordinates = None | ||
108 | for (x0, y0, _, _, x1, y1, _, _), text in go_res.values(): | 106 | for (x0, y0, _, _, x1, y1, _, _), text in go_res.values(): |
109 | cent_x = x0 + ((x1 - x0)/2) | 107 | cent_x = x0 + ((x1 - x0)/2) |
110 | cent_y = y0 + ((y1 - y0)/2) | 108 | cent_y = y0 + ((y1 - y0)/2) |
111 | if x_min < cent_x < x_max and y_min < cent_y < y_max: | 109 | if x_min < cent_x < x_max and y_min < cent_y < y_max: |
112 | if y_min_find is None or y0 < y_min_find: | 110 | if len(text.strip()) > 0: |
113 | if len(text.strip()) > 0: | 111 | find_list.append(cent_x, cent_y, x0, y0, x1, y1, text) |
114 | y_min_find = y0 | 112 | if len(find_list) == 0: |
115 | value = text | 113 | return None, None |
116 | coordinates = (x0, y0, x1, y1) | 114 | else: |
117 | return value, coordinates | 115 | find_list.sort(key=lambda x: (x[1], x[0])) |
116 | coordinates = find_list[0][2: 6] | ||
117 | if append: | ||
118 | value = ''.join([text for _, _, _, _, _, _, text in find_list]) | ||
119 | else: | ||
120 | value = find_list[0][-1] | ||
121 | return value, coordinates | ||
118 | 122 | ||
119 | @staticmethod | 123 | @staticmethod |
120 | def rebuild_res(value_res, coordinates_res, is_signature=False): | 124 | def rebuild_res(value_res, coordinates_res, is_signature=False): | ... | ... |
-
Please register or sign in to post a comment