Spaces:
Runtime error
Runtime error
Updates
Browse files
app.py
CHANGED
|
@@ -31,11 +31,10 @@ print('ocr engine init: ', ocrRet.decode('utf-8'))
|
|
| 31 |
|
| 32 |
@app.route('/ocr/idcard', methods=['POST'])
|
| 33 |
def ocr_idcard():
|
| 34 |
-
print(request.files)
|
| 35 |
file1 = request.files['image1']
|
| 36 |
|
| 37 |
file_name1 = uuid.uuid4().hex[:6]
|
| 38 |
-
save_path1 =
|
| 39 |
file1.save(save_path1)
|
| 40 |
|
| 41 |
file_path1 = os.path.abspath(save_path1)
|
|
@@ -46,9 +45,8 @@ def ocr_idcard():
|
|
| 46 |
file2 = request.files['image2']
|
| 47 |
|
| 48 |
file_name2 = uuid.uuid4().hex[:6]
|
| 49 |
-
save_path2 =
|
| 50 |
file2.save(save_path2)
|
| 51 |
-
print(file2.filename)
|
| 52 |
|
| 53 |
file_path2 = os.path.abspath(save_path2)
|
| 54 |
|
|
@@ -74,7 +72,7 @@ def ocr_idcard_base64():
|
|
| 74 |
imageBase64 = content['image']
|
| 75 |
|
| 76 |
file_name = uuid.uuid4().hex[:6]
|
| 77 |
-
save_path =
|
| 78 |
with open(save_path, "wb") as fh:
|
| 79 |
fh.write(base64.b64decode(imageBase64))
|
| 80 |
|
|
@@ -97,11 +95,10 @@ def ocr_idcard_base64():
|
|
| 97 |
@app.route('/ocr/credit', methods=['POST'])
|
| 98 |
def ocr_credit():
|
| 99 |
file = request.files['image']
|
| 100 |
-
print('ocr_credit ', file)
|
| 101 |
|
| 102 |
image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
|
| 103 |
file_name = uuid.uuid4().hex[:6]
|
| 104 |
-
save_path =
|
| 105 |
cv2.imwrite(save_path, image)
|
| 106 |
|
| 107 |
file_path = os.path.abspath(save_path)
|
|
@@ -120,13 +117,12 @@ def ocr_credit():
|
|
| 120 |
|
| 121 |
@app.route('/ocr/credit_base64', methods=['POST'])
|
| 122 |
def ocr_credit_base64():
|
| 123 |
-
print('ocr_credit_base64');
|
| 124 |
content = request.get_json()
|
| 125 |
imageBase64 = content['image']
|
| 126 |
image = cv2.imdecode(np.frombuffer(base64.b64decode(imageBase64), dtype=np.uint8), cv2.IMREAD_COLOR)
|
| 127 |
|
| 128 |
file_name = uuid.uuid4().hex[:6]
|
| 129 |
-
save_path =
|
| 130 |
cv2.imwrite(save_path, image)
|
| 131 |
|
| 132 |
file_path = os.path.abspath(save_path)
|
|
@@ -146,11 +142,10 @@ def ocr_credit_base64():
|
|
| 146 |
@app.route('/ocr/barcode', methods=['POST'])
|
| 147 |
def ocr_barcode():
|
| 148 |
file = request.files['image']
|
| 149 |
-
print('ocr_barcode ', file)
|
| 150 |
|
| 151 |
image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
|
| 152 |
file_name = uuid.uuid4().hex[:6]
|
| 153 |
-
save_path =
|
| 154 |
cv2.imwrite(save_path, image)
|
| 155 |
|
| 156 |
file_path = os.path.abspath(save_path)
|
|
@@ -174,11 +169,10 @@ def ocr_barcode_base64():
|
|
| 174 |
image = cv2.imdecode(np.frombuffer(base64.b64decode(imageBase64), dtype=np.uint8), cv2.IMREAD_COLOR)
|
| 175 |
|
| 176 |
file_name = uuid.uuid4().hex[:6]
|
| 177 |
-
save_path =
|
| 178 |
cv2.imwrite(save_path, image)
|
| 179 |
|
| 180 |
file_path = os.path.abspath(save_path)
|
| 181 |
-
print('file_path: ', file_path)
|
| 182 |
|
| 183 |
ocrResult = TTVOcrBarCode(file_path.encode('utf-8'))
|
| 184 |
ocrResDict = json.loads(ocrResult)
|
|
|
|
| 31 |
|
| 32 |
@app.route('/ocr/idcard', methods=['POST'])
|
| 33 |
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 |
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)
|
| 52 |
|
|
|
|
| 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 |
@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 |
|
| 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 |
@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 |
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)
|