mirror of
https://github.com/RapidAI/RapidOCR.git
synced 2026-11-11 13:30:51 +08:00
39 lines
952 B
Python
39 lines
952 B
Python
# -*- encoding: utf-8 -*-
|
|
# @Author: SWHL
|
|
# @Contact: liekkaskono@163.com
|
|
import base64
|
|
from wsgiref.simple_server import make_server
|
|
|
|
import cv2
|
|
import numpy as np
|
|
from flask import Flask, request
|
|
|
|
from task import detect_recognize
|
|
|
|
app = Flask(__name__)
|
|
app.config['MAX_CONTENT_LENGTH'] = 3 * 1024 * 1024
|
|
|
|
|
|
@app.route('/ocr', methods=['POST'])
|
|
def ocr():
|
|
if request.method == 'POST':
|
|
url_get = request.get_json()
|
|
img_str = url_get.get('file')
|
|
|
|
image = base64.b64decode(img_str + '=' * (-len(img_str) % 4))
|
|
nparr = np.frombuffer(image, np.uint8)
|
|
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
|
if image.ndim == 2:
|
|
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
|
|
|
|
rec_res_data = detect_recognize(image, is_api=True)
|
|
return rec_res_data
|
|
|
|
|
|
if __name__ == '__main__':
|
|
ip = '0.0.0.0'
|
|
ip_port = 9003
|
|
|
|
server = make_server(ip, ip_port, app)
|
|
server.serve_forever()
|