Delete test.py
Showing
1 changed file
with
0 additions
and
114 deletions
src/pos/test.py
deleted
100644 → 0
1 | import json | ||
2 | |||
3 | import requests | ||
4 | import logging | ||
5 | import base64 | ||
6 | |||
7 | logger = logging.getLogger() | ||
8 | |||
9 | |||
10 | def de_mortgage_ocr_process(img_base64): | ||
11 | result_obj = { | ||
12 | 'customerName': '', | ||
13 | 'application': '', | ||
14 | 'deMortgageDate': '' | ||
15 | } | ||
16 | url = 'http://file-classification.situdata.com/bs/all' | ||
17 | json_data = {"file": img_base64, "classify": 28, "version": "green"} | ||
18 | try: | ||
19 | response = requests.post(url, json=json_data) | ||
20 | response.encoding = 'unicode_escape' | ||
21 | ocr_res = response.json() | ||
22 | print(ocr_res) | ||
23 | # ocr_res = ocr_res.decode('unicode_escape') | ||
24 | data = ocr_res.get('data', []) | ||
25 | for classify_data in data: | ||
26 | result_data = classify_data.get('data', {}) | ||
27 | results = result_data.get('results') | ||
28 | if result_data.get('page', '') == 'VehicleRegArea': | ||
29 | if results.get('register_type', -1) == 1: | ||
30 | info = results.get('解除抵押日期', {}) | ||
31 | result_obj['deMortgageDate'] = info.get('words', '') | ||
32 | elif results.get('register_type', -1) == 0: | ||
33 | info = results.get('抵押权人姓名/名称', {}) | ||
34 | result_obj['application'] = info.get('words', '') | ||
35 | |||
36 | elif result_data.get('page', '') == 'VehicleRCI': | ||
37 | print('----------------------') | ||
38 | info = results.get('1.机动车所有人/身份证名称/号码', {}) | ||
39 | result_obj['customerName'] = info.get('words', '').split('/')[0] | ||
40 | |||
41 | except Exception as e: | ||
42 | logger.error(e) | ||
43 | # LoggerMixin.running_log.error('[PosHandler de_mortgage_ocr_process] [error={0}]'.format(e.format_exc())) | ||
44 | result_obj = { | ||
45 | 'customerName': '', | ||
46 | 'application': '', | ||
47 | 'deMortgageDate': '' | ||
48 | } | ||
49 | return result_obj | ||
50 | |||
51 | |||
52 | de_mortgage_comments = { | ||
53 | 'customerName': ('机动车所有人识别不一致', ), | ||
54 | 'application': ('抵押权人姓名/名称识别不一致', ), | ||
55 | 'deMortgageDate': ('解除抵押日期不一致', ) | ||
56 | } | ||
57 | |||
58 | |||
59 | def view(args): | ||
60 | img_files = args.get('file_base64', []) | ||
61 | customer_name = args.get('customerName', '') | ||
62 | application = args.get('application', '') | ||
63 | de_mortgage_date = args.get('deMortgageDate') | ||
64 | |||
65 | fields_input = { | ||
66 | 'customerName': customer_name, | ||
67 | 'application': application, | ||
68 | 'deMortgageDate': de_mortgage_date | ||
69 | } | ||
70 | de_mortgage_info = {} | ||
71 | # 绿本必须分开ocr | ||
72 | for img_file in img_files: | ||
73 | info = de_mortgage_ocr_process(img_file) | ||
74 | de_mortgage_info.update(info) | ||
75 | |||
76 | request_pass = True | ||
77 | fields_result = [] | ||
78 | for field_name, input_val in fields_input.items(): | ||
79 | field_result = { | ||
80 | "name": field_name, | ||
81 | "input": input_val, | ||
82 | "ocr": de_mortgage_info.get(field_name, ''), | ||
83 | "field_is_pass": False, | ||
84 | "comments": '' | ||
85 | } | ||
86 | # result, _ = cp.common_compare(field_result['input'], field_result['ocr']) | ||
87 | # if result == cp.RESULT_Y: | ||
88 | # fields_result['field_is_pass'] = result | ||
89 | # else: | ||
90 | # request_pass = False | ||
91 | # fields_result['comments'] = de_mortgage_comments.get(field_name, '') | ||
92 | |||
93 | fields_result.append(field_result) | ||
94 | |||
95 | result = { | ||
96 | "is_pass": request_pass, | ||
97 | "fields": fields_result | ||
98 | } | ||
99 | print(result) | ||
100 | |||
101 | |||
102 | if __name__ == '__main__': | ||
103 | # print(u'编号'.encode('ascii')) | ||
104 | # print(b"\u7f16\u53f7".decode('unicode_escape')) | ||
105 | img_base64 = r'C:\Users\EDY\Desktop\1280X1280 (1).PNG' | ||
106 | # img_base64 = r'C:\Users\EDY\Desktop\1280X1280.PNG' | ||
107 | with open(img_base64, 'rb') as f: | ||
108 | content = f.read() | ||
109 | args = { | ||
110 | 'file_base64': [str(base64.b64encode(content), 'utf-8')] | ||
111 | } | ||
112 | view(args) | ||
113 | |||
114 |
-
Please register or sign in to post a comment