写了个本地服务器 POST url="“http://127.0.0.1:9527/api/code”" json提交{"base":"图片base"}
[Python] 纯文本查看 复制代码 import base64
import ctypes
import os
from flask import Flask, request, jsonify
app = Flask(__name__)
current_directory = os.getcwd()
path = os.path.join(current_directory, 'res\\ocr.dll')
if os.path.exists(path):
example_dll = ctypes.CDLL(path)
example_dll.init()
functions = [func for func in dir(example_dll) if callable(getattr(example_dll, func))]
dist = []
for func in functions:
dist.append(func)
def init(base64_str):
byte_data = base64.b64decode(base64_str)
length = len(str(byte_data))
ocr_result = example_dll.ocr(byte_data, length)
int_value = ocr_result
pointer = ctypes.cast(int_value, ctypes.POINTER(ctypes.c_char))
content = ctypes.string_at(pointer)
return content.decode('utf-8')
@app.route('/api/code', methods=['POST'])
def get_data():
base64_str = request.json.get("base")
if base64_str:
ret_code = init(base64_str)
return jsonify({
"ret_code": ret_code
})
else:
return jsonify({
"code": 400,
"error": "Base64 string not provided."
}), 400
if __name__ == '__main__':
app.run(port=9527) |