591d1ac9 by 周伟奇

add ic true/false

1 parent 789f8e25
...@@ -624,7 +624,9 @@ OTHER_CLASSIFY = 2 ...@@ -624,7 +624,9 @@ OTHER_CLASSIFY = 2
624 # 身份证 624 # 身份证
625 IC_CN_NAME = '身份证' 625 IC_CN_NAME = '身份证'
626 IC_CLASSIFY = 33 626 IC_CLASSIFY = 33
627 IC_FIELD_ORDER_0 = (('姓名', '姓名'), 627 IC_TURE_OR_FALSE = '真伪'
628 IC_FIELD_ORDER_0 = ((IC_TURE_OR_FALSE, '身份证'),
629 ('姓名', '姓名'),
628 ('公民身份号码', '公民身份号码'), 630 ('公民身份号码', '公民身份号码'),
629 ('出生年月', '出生年月'), 631 ('出生年月', '出生年月'),
630 ('住址', '住址'), 632 ('住址', '住址'),
...@@ -934,3 +936,10 @@ PATTERN_LIST = ['交易名称', '收入/支出金额', '收入', '存入', '支 ...@@ -934,3 +936,10 @@ PATTERN_LIST = ['交易名称', '收入/支出金额', '收入', '存入', '支
934 '短摘要', '本次余额', '交易后余额', '交易说明', '帐户余额', '交易日期 记账日期'] 936 '短摘要', '本次余额', '交易后余额', '交易说明', '帐户余额', '交易日期 记账日期']
935 937
936 CN_RE = re.compile(u'[\u4e00-\u9fa5]') 938 CN_RE = re.compile(u'[\u4e00-\u9fa5]')
939
940 IC_RES_MAPPING = {
941 -2: '不是有效证件',
942 -1: '无法判断',
943 0: '伪造证件',
944 1: '真实证件',
945 }
......
...@@ -8,3 +8,7 @@ class OCR1Exception(Exception): ...@@ -8,3 +8,7 @@ class OCR1Exception(Exception):
8 8
9 class OCR2Exception(Exception): 9 class OCR2Exception(Exception):
10 pass 10 pass
11
12
13 class OCR4Exception(Exception):
14 pass
......
...@@ -23,7 +23,7 @@ from common.tools.pdf_to_img import PDFHandler ...@@ -23,7 +23,7 @@ from common.tools.pdf_to_img import PDFHandler
23 from apps.doc import consts 23 from apps.doc import consts
24 from apps.doc.ocr.edms import EDMS, rh 24 from apps.doc.ocr.edms import EDMS, rh
25 from apps.doc.named_enum import KeywordsType 25 from apps.doc.named_enum import KeywordsType
26 from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception 26 from apps.doc.exceptions import EDMSException, OCR1Exception, OCR2Exception, OCR4Exception
27 from apps.doc.ocr.wb import BSWorkbook, Workbook 27 from apps.doc.ocr.wb import BSWorkbook, Workbook
28 from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords 28 from apps.doc.models import DocStatus, HILDoc, AFCDoc, Keywords
29 29
...@@ -48,6 +48,7 @@ class Command(BaseCommand, LoggerMixin): ...@@ -48,6 +48,7 @@ class Command(BaseCommand, LoggerMixin):
48 self.ocr_1_urls = conf.get_namespace('OCR_URL_1_') 48 self.ocr_1_urls = conf.get_namespace('OCR_URL_1_')
49 self.ocr_url_2 = conf.OCR_URL_2 49 self.ocr_url_2 = conf.OCR_URL_2
50 self.ocr_url_3 = conf.BC_URL 50 self.ocr_url_3 = conf.BC_URL
51 self.ocr_url_4 = conf.IC_URL
51 # EDMS web_service_api 52 # EDMS web_service_api
52 self.edms = EDMS() 53 self.edms = EDMS()
53 # 优雅退出信号:15 54 # 优雅退出信号:15
...@@ -189,13 +190,60 @@ class Command(BaseCommand, LoggerMixin): ...@@ -189,13 +190,60 @@ class Command(BaseCommand, LoggerMixin):
189 else: 190 else:
190 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) 191 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
191 192
192 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx): 193 def license1_process(self, ocr_data, license_summary, classify, res_list, pno, ino, part_idx, img_path):
193 # 类别:'0'身份证, '1'居住证 194 # 类别:'0'身份证, '1'居住证
194 license_data = ocr_data.get('data', []) 195 license_data = ocr_data.get('data', [])
195 if not license_data: 196 if not license_data:
196 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY)) 197 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_EMPTY))
197 return 198 return
198 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS)) 199 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS))
200 if classify == consts.IC_CLASSIFY:
201 for id_card_dict in license_data:
202 try:
203 base64_img = id_card_dict.pop('base64_img')
204 except Exception as e:
205 continue
206 else:
207 card_type = -1
208 json_data_4 = {
209 'mode': 1,
210 'user_info': {
211 'image_content': base64_img,
212 },
213 'options': {
214 'distinguish_type': 1,
215 'auto_rotate': True,
216 },
217 }
218 for times in range(consts.RETRY_TIMES):
219 try:
220 start_time = time.time()
221 ocr_4_response = requests.post(self.ocr_url_4, json=json_data_4)
222 if ocr_4_response.status_code != 200:
223 raise OCR4Exception('ocr_4 status code: {0}'.format(ocr_4_response.status_code))
224 except Exception as e:
225 self.cronjob_log.warn(
226 '{0} [ocr_4 failed] [times={1}] [img_path={2}] [error={3}]'.format(
227 self.log_base, times, img_path, traceback.format_exc()))
228 else:
229 ocr_4_res = json.loads(ocr_4_response.json())
230 end_time = time.time()
231 speed_time = int(end_time - start_time)
232
233 if ocr_4_res.get('code') == 0 and ocr_4_res.get('result', {}).get('rtn') == 0:
234 card_type = ocr_4_res.get('result', {}).get(
235 'idcard_distinguish_result', {}).get('result', -1)
236
237 self.cronjob_log.info(
238 '{0} [ocr_4 success] [img_path={1}] [speed_time={2}]'.format(
239 self.log_base, img_path, speed_time))
240
241 break
242 else:
243 self.cronjob_log.warn(
244 '{0} [ocr_4 failed] [img_path={1}]'.format(self.log_base, img_path))
245
246 id_card_dict[consts.IC_TURE_OR_FALSE] = consts.IC_RES_MAPPING.get(card_type)
199 license_summary.setdefault(classify, []).extend(license_data) 247 license_summary.setdefault(classify, []).extend(license_data)
200 248
201 def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx): 249 def license2_process(self, ocr_res_2, license_summary, pid, classify, res_list, pno, ino, part_idx):
...@@ -559,7 +607,8 @@ class Command(BaseCommand, LoggerMixin): ...@@ -559,7 +607,8 @@ class Command(BaseCommand, LoggerMixin):
559 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER)) 607 res_list.append((pno, ino, part_idx, consts.RES_SUCCESS_OTHER))
560 continue 608 continue
561 elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1 609 elif classify in consts.LICENSE_CLASSIFY_SET_1: # 证件1
562 self.license1_process(ocr_data, license_summary, classify, res_list, pno, ino, part_idx) 610 self.license1_process(ocr_data, license_summary, classify, res_list,
611 pno, ino, part_idx, img_path)
563 elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2 612 elif classify in consts.LICENSE_CLASSIFY_SET_2: # 证件2
564 pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify) 613 pid, _, _, _, _, _ = consts.LICENSE_CLASSIFY_MAPPING.get(classify)
565 file_data = ocr_data.get('section_img') 614 file_data = ocr_data.get('section_img')
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!