Turing311 commited on
Commit
2595a43
·
1 Parent(s): bb46f72
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -34,7 +34,7 @@ def ocr_idcard():
34
  file1 = request.files['image1']
35
 
36
  file_name1 = uuid.uuid4().hex[:6]
37
- save_path1 = file_name1 + '_' + file1.filename
38
  file1.save(save_path1)
39
 
40
  file_path1 = os.path.abspath(save_path1)
@@ -45,7 +45,7 @@ def ocr_idcard():
45
  file2 = request.files['image2']
46
 
47
  file_name2 = uuid.uuid4().hex[:6]
48
- save_path2 = file_name2 + '_' + file2.filename
49
  file2.save(save_path2)
50
 
51
  file_path2 = os.path.abspath(save_path2)
@@ -72,7 +72,7 @@ def ocr_idcard_base64():
72
  imageBase64 = content['image']
73
 
74
  file_name = uuid.uuid4().hex[:6]
75
- save_path = file_name
76
  with open(save_path, "wb") as fh:
77
  fh.write(base64.b64decode(imageBase64))
78
 
@@ -95,10 +95,11 @@ def ocr_idcard_base64():
95
  @app.route('/ocr/credit', methods=['POST'])
96
  def ocr_credit():
97
  file = request.files['image']
 
98
 
99
  image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
100
  file_name = uuid.uuid4().hex[:6]
101
- save_path = file_name + '.png'
102
  cv2.imwrite(save_path, image)
103
 
104
  file_path = os.path.abspath(save_path)
@@ -117,12 +118,13 @@ def ocr_credit():
117
 
118
  @app.route('/ocr/credit_base64', methods=['POST'])
119
  def ocr_credit_base64():
 
120
  content = request.get_json()
121
  imageBase64 = content['image']
122
  image = cv2.imdecode(np.frombuffer(base64.b64decode(imageBase64), dtype=np.uint8), cv2.IMREAD_COLOR)
123
 
124
  file_name = uuid.uuid4().hex[:6]
125
- save_path = file_name + '.png'
126
  cv2.imwrite(save_path, image)
127
 
128
  file_path = os.path.abspath(save_path)
@@ -142,10 +144,11 @@ def ocr_credit_base64():
142
  @app.route('/ocr/barcode', methods=['POST'])
143
  def ocr_barcode():
144
  file = request.files['image']
 
145
 
146
  image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
147
  file_name = uuid.uuid4().hex[:6]
148
- save_path = file_name + '.png'
149
  cv2.imwrite(save_path, image)
150
 
151
  file_path = os.path.abspath(save_path)
@@ -169,10 +172,11 @@ def ocr_barcode_base64():
169
  image = cv2.imdecode(np.frombuffer(base64.b64decode(imageBase64), dtype=np.uint8), cv2.IMREAD_COLOR)
170
 
171
  file_name = uuid.uuid4().hex[:6]
172
- save_path = file_name + '.png'
173
  cv2.imwrite(save_path, image)
174
 
175
  file_path = os.path.abspath(save_path)
 
176
 
177
  ocrResult = TTVOcrBarCode(file_path.encode('utf-8'))
178
  ocrResDict = json.loads(ocrResult)
 
34
  file1 = request.files['image1']
35
 
36
  file_name1 = uuid.uuid4().hex[:6]
37
+ save_path1 = '/tmp/' + file_name1 + '_' + file1.filename
38
  file1.save(save_path1)
39
 
40
  file_path1 = os.path.abspath(save_path1)
 
45
  file2 = request.files['image2']
46
 
47
  file_name2 = uuid.uuid4().hex[:6]
48
+ save_path2 = '/tmp/' + file_name2 + '_' + file2.filename
49
  file2.save(save_path2)
50
 
51
  file_path2 = os.path.abspath(save_path2)
 
72
  imageBase64 = content['image']
73
 
74
  file_name = uuid.uuid4().hex[:6]
75
+ save_path = '/tmp/' + file_name
76
  with open(save_path, "wb") as fh:
77
  fh.write(base64.b64decode(imageBase64))
78
 
 
95
  @app.route('/ocr/credit', methods=['POST'])
96
  def ocr_credit():
97
  file = request.files['image']
98
+ print('ocr_credit ', file)
99
 
100
  image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
101
  file_name = uuid.uuid4().hex[:6]
102
+ save_path = '/tmp/' + file_name + '.png'
103
  cv2.imwrite(save_path, image)
104
 
105
  file_path = os.path.abspath(save_path)
 
118
 
119
  @app.route('/ocr/credit_base64', methods=['POST'])
120
  def ocr_credit_base64():
121
+ print('ocr_credit_base64');
122
  content = request.get_json()
123
  imageBase64 = content['image']
124
  image = cv2.imdecode(np.frombuffer(base64.b64decode(imageBase64), dtype=np.uint8), cv2.IMREAD_COLOR)
125
 
126
  file_name = uuid.uuid4().hex[:6]
127
+ save_path = '/tmp/' + file_name + '.png'
128
  cv2.imwrite(save_path, image)
129
 
130
  file_path = os.path.abspath(save_path)
 
144
  @app.route('/ocr/barcode', methods=['POST'])
145
  def ocr_barcode():
146
  file = request.files['image']
147
+ print('ocr_barcode ', file)
148
 
149
  image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
150
  file_name = uuid.uuid4().hex[:6]
151
+ save_path = '/tmp/' + file_name + '.png'
152
  cv2.imwrite(save_path, image)
153
 
154
  file_path = os.path.abspath(save_path)
 
172
  image = cv2.imdecode(np.frombuffer(base64.b64decode(imageBase64), dtype=np.uint8), cv2.IMREAD_COLOR)
173
 
174
  file_name = uuid.uuid4().hex[:6]
175
+ save_path = '/tmp/' + file_name + '.png'
176
  cv2.imwrite(save_path, image)
177
 
178
  file_path = os.path.abspath(save_path)
179
+ print('file_path: ', file_path)
180
 
181
  ocrResult = TTVOcrBarCode(file_path.encode('utf-8'))
182
  ocrResDict = json.loads(ocrResult)