086507c6 by 周伟奇

rebuild result

1 parent 5c08056d
...@@ -658,6 +658,13 @@ CLASSIFY_HEADER_LIST = [ ...@@ -658,6 +658,13 @@ CLASSIFY_HEADER_LIST = [
658 OTHER_CLASSIFY = 2 658 OTHER_CLASSIFY = 2
659 659
660 # 身份证 660 # 身份证
661 IC_MAP_0 = (('姓名', '姓名'),
662 ('公民身份号码', '公民身份号码'),
663 ('出生年月', '出生'),
664 ('住址', '住址'),
665 ('性别', '性别'),
666 ('民族', '民族'),)
667 IC_MAP_1 = (('签发机关', '签发机关'),)
661 IC_CN_NAME = '身份证' 668 IC_CN_NAME = '身份证'
662 IC_CLASSIFY = 33 669 IC_CLASSIFY = 33
663 IC_TURE_OR_FALSE = '真伪' 670 IC_TURE_OR_FALSE = '真伪'
...@@ -670,6 +677,12 @@ IC_FIELD_ORDER_0 = ((IC_TURE_OR_FALSE, '身份证'), ...@@ -670,6 +677,12 @@ IC_FIELD_ORDER_0 = ((IC_TURE_OR_FALSE, '身份证'),
670 ('民族', '民族'),) 677 ('民族', '民族'),)
671 IC_FIELD_ORDER_1 = ((IC_TURE_OR_FALSE, '身份证'), ('有效期限', '有效期限'), ('签发机关', '签发机关'),) 678 IC_FIELD_ORDER_1 = ((IC_TURE_OR_FALSE, '身份证'), ('有效期限', '有效期限'), ('签发机关', '签发机关'),)
672 # 居住证 679 # 居住证
680 RP_MAP_0 = (('姓名', '姓名'),
681 ('公民身份号码', '公民身份号码'),
682 ('出生年月', '出生'),
683 ('住址', '住址'),
684 ('性别', '性别'),)
685 RP_MAP_1 = (('签发机关', '签发机关'), ('通行证号码', '通行证号码'))
673 RP_CN_NAME = '居住证' 686 RP_CN_NAME = '居住证'
674 RP_CLASSIFY = 10087 687 RP_CLASSIFY = 10087
675 RP_FIELD_ORDER_0 = (('姓名', '姓名'), 688 RP_FIELD_ORDER_0 = (('姓名', '姓名'),
......
...@@ -246,6 +246,59 @@ class Command(BaseCommand, LoggerMixin): ...@@ -246,6 +246,59 @@ class Command(BaseCommand, LoggerMixin):
246 # contract_result.setdefault(page_num, []).append(rebuild_page_info) 246 # contract_result.setdefault(page_num, []).append(rebuild_page_info)
247 contract_result.setdefault(classify, dict()).setdefault(page_num, []).append(rebuild_page_info) 247 contract_result.setdefault(classify, dict()).setdefault(page_num, []).append(rebuild_page_info)
248 248
249 # def rebuild_result(self, ocr_data, classify, img_path):
250 # license_data = ocr_data.get('data')
251 # if not license_data:
252 # return
253 # if classify == consts.IC_CLASSIFY:
254 # rebuild_data_dict = {}
255 # card_type = license_data.get('type', '')
256 # is_ic = card_type.startswith('身份证')
257 # is_info_side = card_type.endswith('信息面')
258 # rebuild_data_dict['类别'] = '0' if is_ic else '1'
259 # if is_ic:
260 # field_map = consts.IC_MAP_0 if is_info_side else consts.IC_MAP_1
261 # else:
262 # field_map = consts.RP_MAP_0 if is_info_side else consts.RP_MAP_1
263 # for write_field, search_field in field_map:
264 # rebuild_data_dict[write_field] = license_data.get('words_result', {}).get(search_field, {}).get('words', '')
265 # if not is_info_side:
266 # start_time = license_data.get('words_result', {}).get('签发日期', {}).get('words', '')
267 # end_time = license_data.get('words_result', {}).get('失效日期', {}).get('words', '')
268 # rebuild_data_dict['有效期限'] = '{0}-{1}'.format(start_time, end_time)
269 # return [rebuild_data_dict]
270 # elif classify == consts.MVC_CLASSIFY:
271 # # license_data[consts.IMG_PATH_KEY] = img_path
272 # rebuild_data_dict = {}
273 # mvc_page = license_data.pop('page', 'VehicleRCI')
274 # mvc_res = license_data.pop('results', {})
275 # if mvc_page == 'VehicleRegArea':
276 # rebuild_data_dict['机动车登记证书编号'] = mvc_res.get('机动车登记证书编号', {}).get('words', '')
277 # for register_info in mvc_res.get('登记信息', []):
278 # register_info.pop('register_type', None)
279 # register_info.pop('register_type_name', None)
280 # for cn_key, detail_dict in register_info.items():
281 # rebuild_data_dict.setdefault(cn_key, []).append(
282 # detail_dict.get('words', ''))
283 # else:
284 # for cn_key, detail_dict in mvc_res.items():
285 # rebuild_data_dict[cn_key] = detail_dict.get('words', '')
286 # del mvc_res
287 # return [rebuild_data_dict]
288 # elif classify == consts.MVI_CLASSIFY:
289 # rebuild_data_dict = {}
290 # mvi_res = license_data.pop('result', {})
291 # for en_key, detail_dict in mvi_res.items():
292 # rebuild_data_dict[detail_dict.get('chinese_key', '')] = detail_dict.get('words', '')
293 # return [rebuild_data_dict]
294 # elif classify == consts.UCI_CLASSIFY:
295 # rebuild_data_dict = {}
296 # mvi_res = license_data.pop('result', {})
297 # for en_key, detail_dict in mvi_res.items():
298 # rebuild_data_dict[detail_dict.get('chinese_key', '')] = detail_dict.get('words', '')
299 # return [rebuild_data_dict]
300
301
249 302
250 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping): 303 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx, img_path, do_dda, dda_id_bc_mapping):
251 # 类别:'0'身份证, '1'居住证 304 # 类别:'0'身份证, '1'居住证
...@@ -253,7 +306,8 @@ class Command(BaseCommand, LoggerMixin): ...@@ -253,7 +306,8 @@ class Command(BaseCommand, LoggerMixin):
253 if not license_data: 306 if not license_data:
254 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) 307 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
255 return 308 return
256 if classify == consts.INSURANCE_CLASSIFY: # 保单处理 309 # 保单
310 if classify == consts.INSURANCE_CLASSIFY:
257 product_result = ['', '', ''] 311 product_result = ['', '', '']
258 for product in license_data.get('result', {}).get('productList', []): 312 for product in license_data.get('result', {}).get('productList', []):
259 name = product.get('name', {}).get('words', '') 313 name = product.get('name', {}).get('words', '')
...@@ -281,7 +335,8 @@ class Command(BaseCommand, LoggerMixin): ...@@ -281,7 +335,8 @@ class Command(BaseCommand, LoggerMixin):
281 '特别约定第一受益人': special, 335 '特别约定第一受益人': special,
282 } 336 }
283 license_summary.setdefault(classify, []).append(insurance_ocr_result) 337 license_summary.setdefault(classify, []).append(insurance_ocr_result)
284 elif classify == consts.DDA_CLASSIFY: # DDA处理 338 # DDA
339 elif classify == consts.DDA_CLASSIFY:
285 pro = ocr_data.get('confidence', 0) 340 pro = ocr_data.get('confidence', 0)
286 if pro < consts.DDA_PRO_MIN: 341 if pro < consts.DDA_PRO_MIN:
287 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) 342 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
...@@ -291,40 +346,80 @@ class Command(BaseCommand, LoggerMixin): ...@@ -291,40 +346,80 @@ class Command(BaseCommand, LoggerMixin):
291 dda_ocr_result[consts.DDA_PRO] = pro 346 dda_ocr_result[consts.DDA_PRO] = pro
292 dda_ocr_result[consts.IMG_PATH_KEY] = img_path 347 dda_ocr_result[consts.IMG_PATH_KEY] = img_path
293 license_summary.setdefault(classify, []).append(dda_ocr_result) 348 license_summary.setdefault(classify, []).append(dda_ocr_result)
294 elif classify == consts.HMH_CLASSIFY: # 抵押登记豁免函 349 # 抵押登记豁免函
295 hmh_ocr_result = {key: value.get('words', '') for key, value in license_data.items()} 350 elif classify == consts.HMH_CLASSIFY:
351 hmh_ocr_result = {key: value.get('words', '') for key, value in license_data.get('words_result', {}).items()}
296 license_summary.setdefault(classify, []).append(hmh_ocr_result) 352 license_summary.setdefault(classify, []).append(hmh_ocr_result)
297 elif classify == consts.JYPZ_CLASSIFY: # 二手车交易凭证 353 # 二手车交易凭证
354 elif classify == consts.JYPZ_CLASSIFY:
298 jypz_ocr_result = {key: value.get('words', '') for key, value in license_data.get('result', {}).items()} 355 jypz_ocr_result = {key: value.get('words', '') for key, value in license_data.get('result', {}).items()}
299 license_summary.setdefault(classify, []).append(jypz_ocr_result) 356 license_summary.setdefault(classify, []).append(jypz_ocr_result)
300 elif classify == consts.MVC_CLASSIFY: # 车辆登记证 3/4页结果整合 357 # 车辆登记证 3/4页结果整合
301 for mvc_dict in license_data: 358 elif classify == consts.MVC_CLASSIFY:
302 mvc_dict[consts.IMG_PATH_KEY] = img_path 359 rebuild_data_dict = {}
303 try: 360 rebuild_data_dict[consts.IMG_PATH_KEY] = img_path
304 mvc_page = mvc_dict.pop('page') 361 mvc_page = license_data.pop('page', 'VehicleRCI')
305 except Exception as e: 362 mvc_res = license_data.pop('results', {})
306 pass 363 if mvc_page == 'VehicleRegArea':
307 else: 364 rebuild_data_dict['机动车登记证书编号'] = mvc_res.get('机动车登记证书编号', {}).get('words', '')
308 if mvc_page == 'VehicleRegArea': 365 for register_info in mvc_res.get('登记信息', []):
309 mvc_res = mvc_dict.pop('results', {}) 366 register_info.pop('register_type', None)
310 mvc_dict['机动车登记证书编号'] = mvc_res.get('register_no', {}).get('words', '') 367 register_info.pop('register_type_name', None)
311 for register_info in mvc_res.get('register_info', []): 368 for cn_key, detail_dict in register_info.items():
312 for detail_dict in register_info.get('details', {}).values(): 369 rebuild_data_dict.setdefault(cn_key, []).append(
313 mvc_dict.setdefault(detail_dict.get('chinese_key', '未知'), []).append( 370 detail_dict.get('words', ''))
314 detail_dict.get('words', '')) 371 else:
315 del mvc_res 372 for cn_key, detail_dict in mvc_res.items():
316 license_summary.setdefault(classify, []).extend(license_data) 373 rebuild_data_dict[cn_key] = detail_dict.get('words', '')
374 del mvc_res
375 license_summary.setdefault(classify, []).append(rebuild_data_dict)
376
377
378 # for mvc_dict in license_data:
379 # mvc_dict[consts.IMG_PATH_KEY] = img_path
380 # try:
381 # mvc_page = mvc_dict.pop('page')
382 # except Exception as e:
383 # pass
384 # else:
385 # if mvc_page == 'VehicleRegArea':
386 # mvc_res = mvc_dict.pop('results', {})
387 # mvc_dict['机动车登记证书编号'] = mvc_res.get('register_no', {}).get('words', '')
388 # for register_info in mvc_res.get('register_info', []):
389 # for detail_dict in register_info.get('details', {}).values():
390 # mvc_dict.setdefault(detail_dict.get('chinese_key', '未知'), []).append(
391 # detail_dict.get('words', ''))
392 # del mvc_res
393 # license_summary.setdefault(classify, []).extend(license_data)
394
395 # 身份证真伪
396 elif classify == consts.IC_CLASSIFY:
397 id_card_dict = {}
398 card_type = license_data.get('type', '')
399 is_ic = card_type.startswith('身份证')
400 is_info_side = card_type.endswith('信息面')
401 id_card_dict['类别'] = '0' if is_ic else '1'
402 if is_ic:
403 field_map = consts.IC_MAP_0 if is_info_side else consts.IC_MAP_1
404 else:
405 field_map = consts.RP_MAP_0 if is_info_side else consts.RP_MAP_1
406 for write_field, search_field in field_map:
407 id_card_dict[write_field] = license_data.get('words_result', {}).get(search_field, {}).get('words', '')
408 if not is_info_side:
409 start_time = license_data.get('words_result', {}).get('签发日期', {}).get('words', '')
410 end_time = license_data.get('words_result', {}).get('失效日期', {}).get('words', '')
411 id_card_dict['有效期限'] = '{0}-{1}'.format(start_time, end_time)
317 412
318 elif classify == consts.IC_CLASSIFY: # 身份证真伪 413
319 for id_card_dict in license_data: 414 if not is_info_side:
320 if '有效期限' in id_card_dict: 415 id_card_dict[consts.IMG_PATH_KEY_2] = img_path
321 id_card_dict[consts.IMG_PATH_KEY_2] = img_path 416 else:
322 else: 417 id_card_dict[consts.IMG_PATH_KEY] = img_path
323 id_card_dict[consts.IMG_PATH_KEY] = img_path 418 if is_ic:
324 try: 419 try:
325 base64_img = id_card_dict.pop('base64_img') 420 base64_img = license_data.pop('base64_img')
326 except Exception as e: 421 except Exception as e:
327 continue 422 pass
328 else: 423 else:
329 card_type = -1 424 card_type = -1
330 json_data_4 = { 425 json_data_4 = {
...@@ -371,7 +466,14 @@ class Command(BaseCommand, LoggerMixin): ...@@ -371,7 +466,14 @@ class Command(BaseCommand, LoggerMixin):
371 ic_id = id_card_dict[consts.IC_KEY_FIELD[1]].strip() 466 ic_id = id_card_dict[consts.IC_KEY_FIELD[1]].strip()
372 if len(ic_name) > 0 and len(ic_id) > 0: 467 if len(ic_name) > 0 and len(ic_id) > 0:
373 dda_id_bc_mapping.setdefault(consts.IC_FIELD, []).append((ic_name, ic_id, img_path)) 468 dda_id_bc_mapping.setdefault(consts.IC_FIELD, []).append((ic_name, ic_id, img_path))
374 license_summary.setdefault(classify, []).extend(license_data) 469 license_summary.setdefault(classify, []).append(id_card_dict)
470 elif classify == consts.MVI_CLASSIFY or classify == consts.UCI_CLASSIFY:
471 rebuild_data_dict = {}
472 mvi_res = license_data.pop('result', {})
473 for en_key, detail_dict in mvi_res.items():
474 rebuild_data_dict[detail_dict.get('chinese_key', '')] = detail_dict.get('words', '')
475 license_summary.setdefault(classify, []).append(rebuild_data_dict)
476 # 其他
375 else: 477 else:
376 for res_dict in license_data: 478 for res_dict in license_data:
377 res_dict[consts.IMG_PATH_KEY] = img_path 479 res_dict[consts.IMG_PATH_KEY] = img_path
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!