manage.py 1.85 KB
from flask import request, render_template

from flaskr import create_app
from flaskr.biz import user_service
from flaskr.biz.identify_service import IdentifyService
import os

app = create_app()


@app.route("/")
def hello_world():
    return "Hello World!"
    # return render_template("index.html")


@app.route("/yang")
def hello_world_yang():
    yang = request.args.get("name")
    insert_user = user_service.insert_user(yang, 986203)
    print("insert_user===", insert_user.serialize)
    user = user_service.get_user_by_name(yang)
    print("user===", user.serialize)
    return "Hello World yang!"


@app.route("/identify", methods=["POST"])
def identify():
    network_img_path = request.get_json()["img_path"]
    print("network_img_path===", network_img_path)
    plate_number = IdentifyService(network_img_path, None).identify()
    print("plate_number===", plate_number)
    return plate_number if plate_number is not None else "None"


@app.route("/identifyLocal", methods=["POST"])
def identifyLocal():
    local_img_path = request.get_json()["img_path"]
    print("local_img_path===", local_img_path)
    plate_number = IdentifyService(None, local_img_path).identify_local()
    print("plate_number===", plate_number)
    return plate_number if plate_number is not None else "None"


@app.route("/upload", methods=["POST"])
def upload():
    file = request.files["file"]  # 获取上传的文件
    file.save("uploads/" + file.filename)  # 保存文件到指定路径
    local_img_path = "./uploads/" + file.filename
    print("local_img_path===", local_img_path)
    plate_number = IdentifyService(None, local_img_path).identify_local()
    os.remove(local_img_path)
    print("删除图片成功===", local_img_path)
    print("plate_number===", plate_number)
    return plate_number if plate_number is not None else "None"


if __name__ == "__main__":
    app.run(port=5000)