Merge branch 'feature/slice4' into feature/1119
Showing
1 changed file
with
67 additions
and
4 deletions
| ... | @@ -64,6 +64,7 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -64,6 +64,7 @@ class Command(BaseCommand, LoggerMixin): |
| 64 | # ocr相关 | 64 | # ocr相关 |
| 65 | self.ocr_1_urls = conf.get_namespace('OCR_URL_1_') | 65 | self.ocr_1_urls = conf.get_namespace('OCR_URL_1_') |
| 66 | self.ocr_url_2 = conf.OCR_URL_2 | 66 | self.ocr_url_2 = conf.OCR_URL_2 |
| 67 | self.ocr_url_2_bc = conf.OCR_URL_2_BC | ||
| 67 | self.ocr_url_3 = conf.BC_URL | 68 | self.ocr_url_3 = conf.BC_URL |
| 68 | self.ocr_url_4 = conf.IC_URL | 69 | self.ocr_url_4 = conf.IC_URL |
| 69 | # EDMS web_service_api | 70 | # EDMS web_service_api |
| ... | @@ -1212,11 +1213,12 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1212,11 +1213,12 @@ class Command(BaseCommand, LoggerMixin): |
| 1212 | "pid": str(pid), | 1213 | "pid": str(pid), |
| 1213 | "filedata": file_data | 1214 | "filedata": file_data |
| 1214 | } | 1215 | } |
| 1216 | ocr_url_2 = self.ocr_url_2_bc if classify == consts.BC_CLASSIFY else self.ocr_url_2 | ||
| 1215 | 1217 | ||
| 1216 | for times in range(consts.RETRY_TIMES): | 1218 | for times in range(consts.RETRY_TIMES): |
| 1217 | try: | 1219 | try: |
| 1218 | start_time = time.time() | 1220 | start_time = time.time() |
| 1219 | ocr_2_response = requests.post(self.ocr_url_2, data=json_data_2) | 1221 | ocr_2_response = requests.post(ocr_url_2, data=json_data_2) |
| 1220 | if ocr_2_response.status_code != 200: | 1222 | if ocr_2_response.status_code != 200: |
| 1221 | raise OCR2Exception('ocr_2 status code: {0}'.format(ocr_2_response.status_code)) | 1223 | raise OCR2Exception('ocr_2 status code: {0}'.format(ocr_2_response.status_code)) |
| 1222 | except Exception as e: | 1224 | except Exception as e: |
| ... | @@ -1232,10 +1234,69 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1232,10 +1234,69 @@ class Command(BaseCommand, LoggerMixin): |
| 1232 | self.log_base, img_path, speed_time)) | 1234 | self.log_base, img_path, speed_time)) |
| 1233 | 1235 | ||
| 1234 | if classify == consts.BC_CLASSIFY: | 1236 | if classify == consts.BC_CLASSIFY: |
| 1237 | new_ocr_2_res = {} | ||
| 1238 | position_dict = {} | ||
| 1239 | get_info = False | ||
| 1240 | bc_image_data = '' | ||
| 1241 | position = {} | ||
| 1242 | angle = 0 | ||
| 1243 | for page_info in ocr_2_res.get('PageInfo', []): | ||
| 1244 | if get_info: | ||
| 1245 | break | ||
| 1246 | if page_info.get('ErrorCode', 1) in consts.SUCCESS_CODE_SET: | ||
| 1247 | for bc_res_all in page_info.get('Result', []): | ||
| 1248 | if get_info: | ||
| 1249 | break | ||
| 1250 | if bc_res_all.get('ErrorCode', 1) in consts.SUCCESS_CODE_SET: | ||
| 1251 | for bc_res in bc_res_all.get('ResultList', []): | ||
| 1252 | if get_info: | ||
| 1253 | break | ||
| 1254 | get_info = True | ||
| 1255 | bc_image_data = bc_res.get('image_data', '') | ||
| 1256 | position = bc_res.get('position', {}) | ||
| 1257 | angle = bc_res.get('angle', 0) | ||
| 1258 | for field_info in bc_res.get('FieldList', []): | ||
| 1259 | new_ocr_2_res[field_info.get('key', '')] = field_info.get('value', '') | ||
| 1260 | position_dict[field_info.get('key', '')] = { | ||
| 1261 | consts.FIELD_POSITION_KEY: field_info.get('position', {}), | ||
| 1262 | consts.FIELD_QUAD_KEY: field_info.get('quad', []), | ||
| 1263 | } | ||
| 1264 | |||
| 1265 | if get_info: | ||
| 1266 | pre, suf = os.path.splitext(img_path) | ||
| 1267 | if len(bc_image_data) > 0: | ||
| 1268 | position = {} | ||
| 1269 | angle = 0 | ||
| 1270 | section_img_path = '{0}_{1}_0{2}'.format(pre, part_idx, suf) | ||
| 1271 | try: | ||
| 1272 | with open(section_img_path, "wb") as fh: | ||
| 1273 | fh.write(base64.b64decode(bc_image_data.encode())) | ||
| 1274 | except Exception as e: | ||
| 1275 | self.online_log.warn( | ||
| 1276 | '{0} [bc section img save failed] [img_path={1}]' | ||
| 1277 | ' [part_idx={2}]]'.format(self.log_base, img_path, part_idx)) | ||
| 1278 | else: | ||
| 1279 | section_img_path = img_path if ocr_data.get('section_img') is None else '{0}_{1}{2}'.format(pre, part_idx, suf) | ||
| 1280 | if ocr_data.get('section_img') is not None: | ||
| 1281 | try: | ||
| 1282 | with open(section_img_path, "wb") as fh: | ||
| 1283 | fh.write(base64.b64decode(ocr_data.get('section_img').encode())) | ||
| 1284 | except Exception as e: | ||
| 1285 | self.online_log.warn( | ||
| 1286 | '{0} [bc section img save failed] [img_path={1}]' | ||
| 1287 | ' [part_idx={2}]'.format(self.log_base, | ||
| 1288 | img_path, part_idx)) | ||
| 1289 | |||
| 1290 | new_ocr_2_res['ErrorCode'] = 0 | ||
| 1291 | position_dict[consts.POSITION_KEY] = position | ||
| 1292 | position_dict[consts.ANGLE_KEY] = angle | ||
| 1293 | new_ocr_2_res[consts.SECTION_IMG_PATH_KEY] = section_img_path | ||
| 1294 | new_ocr_2_res[consts.ALL_POSITION_KEY] = position_dict | ||
| 1295 | |||
| 1235 | name = '有' | 1296 | name = '有' |
| 1236 | json_data_3 = { | 1297 | json_data_3 = { |
| 1237 | "file": file_data, | 1298 | "file": file_data, |
| 1238 | 'card_res': ocr_2_res | 1299 | 'card_res': new_ocr_2_res |
| 1239 | } | 1300 | } |
| 1240 | card_name_response = requests.post(self.ocr_url_3, json_data_3) | 1301 | card_name_response = requests.post(self.ocr_url_3, json_data_3) |
| 1241 | if card_name_response.status_code == 200: | 1302 | if card_name_response.status_code == 200: |
| ... | @@ -1243,9 +1304,11 @@ class Command(BaseCommand, LoggerMixin): | ... | @@ -1243,9 +1304,11 @@ class Command(BaseCommand, LoggerMixin): |
| 1243 | if isinstance(card_name_res, dict) and \ | 1304 | if isinstance(card_name_res, dict) and \ |
| 1244 | card_name_res.get('data', {}).get('is_exists_name') == 0: | 1305 | card_name_res.get('data', {}).get('is_exists_name') == 0: |
| 1245 | name = '无' | 1306 | name = '无' |
| 1246 | ocr_2_res['Name'] = name | 1307 | new_ocr_2_res['Name'] = name |
| 1308 | else: | ||
| 1309 | new_ocr_2_res = ocr_2_res | ||
| 1247 | 1310 | ||
| 1248 | self.license2_process(ocr_2_res, license_summary, pid, classify, | 1311 | self.license2_process(new_ocr_2_res, license_summary, pid, classify, |
| 1249 | res_list, pno, ino, part_idx, img_path, | 1312 | res_list, pno, ino, part_idx, img_path, |
| 1250 | do_dda, dda_id_bc_mapping, file_data=ocr_data.get('section_img')) | 1313 | do_dda, dda_id_bc_mapping, file_data=ocr_data.get('section_img')) |
| 1251 | break | 1314 | break | ... | ... |
-
Please register or sign in to post a comment