wko-projekt/api.py

40 lines
974 B
Python

# python -m pip install flask
# export FLASK_APP=main.py
# flask run --without-threads
from flask import Flask, request
from yolo import YOLO
import yolo_video
import base64
app = Flask(__name__)
""" Automatic call while FLASK init """
yolo_model = YOLO()
# def deinit_yolo(yolo):
# yolo.close_session()
"""API_address/detectLicense?img="""
@app.get("/detectLicense")
def detectLicensePlate():
# build path
image_path = request.args['img']
# decoded_data = base64.b64decode((image_base64))
# img_file = open('img_to_detect.png', 'wb')
# img_file.write(decoded_data)
# img_file.close()
# P8080275.JPG
# image_path = 'img_to_detect.png'
image_path = './Images/' + image_path
str = yolo_video.detect_license_plate(model=yolo_model, img_path=image_path)
if not base64:
return {
'str': ["None"],
}, 200
else:
return {
'str': str,
}, 200