add left
Showing
1 changed file
with
40 additions
and
23 deletions
... | @@ -110,37 +110,51 @@ class Retriever: | ... | @@ -110,37 +110,51 @@ class Retriever: |
110 | if self.find_keys_list[key_idx] is None: | 110 | if self.find_keys_list[key_idx] is None: |
111 | return | 111 | return |
112 | 112 | ||
113 | _, _, find_key_str, suffix_key, key_x0, key_y0, key_x1, key_y1 = self.find_keys_list[key_idx] | 113 | _, _, find_key_str, suffix_key, key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, \ |
114 | key_x3_src, key_y3_src = self.find_keys_list[key_idx] | ||
114 | 115 | ||
115 | for scope_key_idx in scope_tuple[:-1]: | 116 | for scope_key_idx in scope_tuple[:-1]: |
116 | if self.find_keys_list[scope_key_idx] is None: | 117 | if self.find_keys_list[scope_key_idx] is None: |
117 | continue | 118 | continue |
118 | key_scope = self.find_keys_list[scope_key_idx][6] # left x1 | 119 | key_scope_tuple = ( |
120 | self.find_keys_list[scope_key_idx][6], self.find_keys_list[scope_key_idx][7]) # left x1, y1 | ||
119 | break | 121 | break |
120 | else: | 122 | else: |
121 | key_scope = None | 123 | key_scope_tuple = None |
122 | 124 | ||
123 | if isinstance(if_startswith, str): | 125 | # if isinstance(if_startswith, str): |
124 | if isinstance(suffix_key, str): | 126 | # if isinstance(suffix_key, str): |
125 | # TODO suffix_key校验与修正 | 127 | # # TODO suffix_key校验与修正 |
126 | # TODO 目前只考虑了split的情况 | 128 | # # TODO 目前只考虑了split的情况 |
127 | return suffix_key, key_x0, key_y0, key_x1, key_y1, () | 129 | # if isinstance(length, int): |
130 | # if -3 < length - len(suffix_key) < 3: | ||
131 | # return suffix_key, ( | ||
132 | # key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, | ||
133 | # key_y3_src), () | ||
134 | # else: | ||
135 | # return suffix_key, ( | ||
136 | # key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, | ||
137 | # key_y3_src), () | ||
138 | |||
139 | # 坐标系转换 | ||
140 | cos, sin = self.get_theta(key_x0_src, key_y0_src, key_x1_src, key_y1_src) | ||
141 | key_x0, key_y0, key_x1, key_y1, key_x2, key_y2, key_x3, key_y3 = self.rebuild_coord( | ||
142 | (key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, key_y3_src), cos, | ||
143 | sin) | ||
128 | 144 | ||
129 | height = key_y1 - key_y0 | 145 | height = key_y2 - key_y0 |
130 | y_min = key_y0 - (top_or_left * height) | 146 | y_min = key_y0 - (top_or_left * height) |
131 | y_max = key_y1 + (bottom_or_right * height) | 147 | y_max = key_y2 + (bottom_or_right * height) |
132 | 148 | ||
133 | width = key_x1 - key_x0 | 149 | width = key_x2 - key_x0 |
134 | x_max = key_x0 - (offset * width) | 150 | x_max = key_x0 - (offset * width) |
135 | x_min = x_max - (width * scope_tuple[-1]) if key_scope is None else key_scope | 151 | x_min = x_max - (width * scope_tuple[-1]) if key_scope_tuple is None else \ |
152 | self.rebuild_xy(*key_scope_tuple, cos, sin)[0] | ||
136 | 153 | ||
137 | all_find_value_list = [] | 154 | all_find_value_list = [] |
138 | for go_key_idx, ((x0, y0, _, _, x1, y1, _, _), text) in go_res.items(): | 155 | for go_key_idx, ((x0, y0, x1, y1, x2, y3, x3, y3), text) in go_res.items(): |
139 | cent_x = x0 + ((x1 - x0) / 2) | 156 | cent_x, cent_y = self.rebuild_xy(x0 + ((x2 - x0) / 2), y0 + ((y2 - y0) / 2), cos, sin) |
140 | cent_y = y0 + ((y1 - y0) / 2) | ||
141 | # if go_key_idx == '98' and key_idx == 34: | 157 | # if go_key_idx == '98' and key_idx == 34: |
142 | # print(key_scope) | ||
143 | # print('-------------') | ||
144 | # print(cent_x) | 158 | # print(cent_x) |
145 | # print(cent_y) | 159 | # print(cent_y) |
146 | # print('-----------') | 160 | # print('-----------') |
... | @@ -153,15 +167,15 @@ class Retriever: | ... | @@ -153,15 +167,15 @@ class Retriever: |
153 | # print(x_max) | 167 | # print(x_max) |
154 | # print(y_min) | 168 | # print(y_min) |
155 | # print(y_max) | 169 | # print(y_max) |
156 | # print('===============') | ||
157 | if x_min < cent_x < x_max and y_min < cent_y < y_max: | 170 | if x_min < cent_x < x_max and y_min < cent_y < y_max: |
158 | all_find_value_list.append((text, x0, y0, x1, y1, (go_key_idx, ))) | 171 | all_find_value_list.append((text, x0, y0, x1, y1, x2, y2, x3, y3, (go_key_idx,))) |
159 | 172 | ||
160 | if len(all_find_value_list) == 0: | 173 | if len(all_find_value_list) == 0: |
161 | return | 174 | return |
162 | elif len(all_find_value_list) == 1: | 175 | elif len(all_find_value_list) == 1: |
163 | return all_find_value_list[0] | 176 | return all_find_value_list[0] |
164 | else: | 177 | else: |
178 | # TODO choice时的坐标转换? | ||
165 | choice_value = getattr(self, 'choice_{0}'.format(choice_method))(all_find_value_list, length) | 179 | choice_value = getattr(self, 'choice_{0}'.format(choice_method))(all_find_value_list, length) |
166 | return choice_value | 180 | return choice_value |
167 | 181 | ||
... | @@ -176,7 +190,8 @@ class Retriever: | ... | @@ -176,7 +190,8 @@ class Retriever: |
176 | if self.find_keys_list[key_idx] is None: | 190 | if self.find_keys_list[key_idx] is None: |
177 | return | 191 | return |
178 | 192 | ||
179 | _, _, find_key_str, suffix_key, key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, key_y3_src = self.find_keys_list[key_idx] | 193 | _, _, find_key_str, suffix_key, key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, \ |
194 | key_x3_src, key_y3_src = self.find_keys_list[key_idx] | ||
180 | 195 | ||
181 | for scope_key_idx in scope_tuple[:-1]: | 196 | for scope_key_idx in scope_tuple[:-1]: |
182 | if self.find_keys_list[scope_key_idx] is None: | 197 | if self.find_keys_list[scope_key_idx] is None: |
... | @@ -197,8 +212,9 @@ class Retriever: | ... | @@ -197,8 +212,9 @@ class Retriever: |
197 | return suffix_key, (key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, key_y3_src), () | 212 | return suffix_key, (key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, key_y3_src), () |
198 | 213 | ||
199 | # 坐标系转换 | 214 | # 坐标系转换 |
200 | cos, sin = self.get_theta(x0, y0, x1, y1) | 215 | cos, sin = self.get_theta(key_x0_src, key_y0_src, key_x1_src, key_y1_src) |
201 | key_x0, key_y0, key_x1, key_y1, key_x2, key_y2, key_x3, key_y3 = self.rebuild_coord((key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, key_y3_src), cos, sin) | 216 | key_x0, key_y0, key_x1, key_y1, key_x2, key_y2, key_x3, key_y3 = self.rebuild_coord( |
217 | (key_x0_src, key_y0_src, key_x1_src, key_y1_src, key_x2_src, key_y2_src, key_x3_src, key_y3_src), cos, sin) | ||
202 | 218 | ||
203 | height = key_y2 - key_y0 | 219 | height = key_y2 - key_y0 |
204 | y_min = key_y0 - (top_or_left * height) | 220 | y_min = key_y0 - (top_or_left * height) |
... | @@ -206,7 +222,8 @@ class Retriever: | ... | @@ -206,7 +222,8 @@ class Retriever: |
206 | 222 | ||
207 | width = key_x2 - key_x0 | 223 | width = key_x2 - key_x0 |
208 | x_min = key_x2 + (offset * width) | 224 | x_min = key_x2 + (offset * width) |
209 | x_max = x_min + (width * scope_tuple[-1]) if key_scope_tuple is None else self.rebuild_xy(*key_scope_tuple, cos, sin)[0] | 225 | x_max = x_min + (width * scope_tuple[-1]) if key_scope_tuple is None else self.rebuild_xy( |
226 | *key_scope_tuple, cos, sin)[0] | ||
210 | 227 | ||
211 | all_find_value_list = [] | 228 | all_find_value_list = [] |
212 | for go_key_idx, ((x0, y0, x1, y1, x2, y3, x3, y3), text) in go_res.items(): | 229 | for go_key_idx, ((x0, y0, x1, y1, x2, y3, x3, y3), text) in go_res.items(): | ... | ... |
-
Please register or sign in to post a comment