2023-01-22 21:00:32 +01:00
|
|
|
# python -m pip install flask
|
2023-01-27 00:11:51 +01:00
|
|
|
# export FLASK_APP=api.py
|
2023-01-22 21:00:32 +01:00
|
|
|
# flask run --without-threads
|
|
|
|
|
2023-01-27 00:11:51 +01:00
|
|
|
from flask import Flask, request, jsonify
|
2023-01-22 21:00:32 +01:00
|
|
|
from yolo import YOLO
|
2023-01-27 00:11:51 +01:00
|
|
|
import json
|
2023-01-22 21:00:32 +01:00
|
|
|
import yolo_video
|
|
|
|
import base64
|
2023-01-27 00:11:51 +01:00
|
|
|
import cv2 as cv
|
2023-01-22 21:00:32 +01:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
""" Automatic call while FLASK init """
|
|
|
|
|
2023-01-27 00:11:51 +01:00
|
|
|
|
|
|
|
"""API_address/ping/<int:id>"""
|
|
|
|
@app.route("/ping/<int:id>", methods=["GET"])
|
|
|
|
def get_ping(id: int):
|
|
|
|
print(f'Request for PING {id=} received')
|
|
|
|
id = id + 1
|
|
|
|
return jsonify(id), 200
|
|
|
|
|
|
|
|
"""API_address/test"""
|
|
|
|
@app.get("/test")
|
|
|
|
def test():
|
|
|
|
o = {'str': 'okokok'}
|
|
|
|
return jsonify(o), 200
|
2023-01-22 21:00:32 +01:00
|
|
|
|
|
|
|
"""API_address/detectLicense?img="""
|
2023-01-27 00:11:51 +01:00
|
|
|
@app.route("/detectLicense", methods=['POST'])
|
2023-01-22 21:00:32 +01:00
|
|
|
def detectLicensePlate():
|
2023-01-27 00:11:51 +01:00
|
|
|
yolo_model = YOLO()
|
|
|
|
res = json.loads(request.data)
|
|
|
|
print('ok')
|
|
|
|
|
|
|
|
# decoded data
|
|
|
|
decoded_data = base64.b64decode(res["imageFile"])
|
|
|
|
img_file = open('base64.png', 'wb')
|
|
|
|
img_file.write(decoded_data)
|
|
|
|
img_file.close()
|
|
|
|
image_path = r'base64.png'
|
|
|
|
base64_b = yolo_video.detect_license_plate(model=yolo_model, img_path=image_path, i=0)
|
|
|
|
print(type(str(base64_b)))
|
|
|
|
res = {'str': str(base64_b)}
|
|
|
|
return jsonify(str(base64_b)), 200
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='0.0.0.0', port=8080)
|
|
|
|
|