last changes to API
This commit is contained in:
parent
c1a4151034
commit
e163d25776
24
API/api.py
24
API/api.py
@ -1,5 +1,5 @@
|
|||||||
# python -m pip install flask
|
# python -m pip install flask
|
||||||
# export FLASK_APP=api.py
|
# export FLASK_APP=API/api.py
|
||||||
# flask run --without-threads
|
# flask run --without-threads
|
||||||
|
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
@ -9,11 +9,8 @@ import yolo_video
|
|||||||
import base64
|
import base64
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
yolo_model = YOLO()
|
||||||
|
|
||||||
""" Automatic call while FLASK init """
|
|
||||||
|
|
||||||
# def deinit_yolo(yolo):
|
|
||||||
# yolo.close_session()
|
|
||||||
|
|
||||||
"""API_address/ping/<int:id>"""
|
"""API_address/ping/<int:id>"""
|
||||||
@app.route("/ping/<int:id>", methods=["GET"])
|
@app.route("/ping/<int:id>", methods=["GET"])
|
||||||
@ -30,15 +27,14 @@ def test():
|
|||||||
|
|
||||||
@app.route('/getPlatesNumber', methods=['POST'])
|
@app.route('/getPlatesNumber', methods=['POST'])
|
||||||
def getPlatesNumber():
|
def getPlatesNumber():
|
||||||
yolo_model = YOLO()
|
|
||||||
res = json.loads(request.data)
|
res = json.loads(request.data)
|
||||||
|
|
||||||
# decoded data
|
# decoded data
|
||||||
decoded_data = base64.b64decode(res["imageFile"])
|
decoded_data = base64.b64decode(res["imageFile"])
|
||||||
img_file = open('base64.png', 'wb')
|
img_file = open('API/base64.png', 'wb')
|
||||||
img_file.write(decoded_data)
|
img_file.write(decoded_data)
|
||||||
img_file.close()
|
img_file.close()
|
||||||
image_path = r'base64.png'
|
image_path = r'API/base64.png'
|
||||||
base64_b, texts = yolo_video.detect_license_plate(model=yolo_model, img_path=image_path, i=0)
|
base64_b, texts = yolo_video.detect_license_plate(model=yolo_model, img_path=image_path, i=0)
|
||||||
res = {'platesNumber': texts}
|
res = {'platesNumber': texts}
|
||||||
return jsonify(res), 200
|
return jsonify(res), 200
|
||||||
@ -46,18 +42,20 @@ def getPlatesNumber():
|
|||||||
"""API_address/detectLicense?img="""
|
"""API_address/detectLicense?img="""
|
||||||
@app.route("/detectLicense", methods=['POST'])
|
@app.route("/detectLicense", methods=['POST'])
|
||||||
def detectLicensePlate():
|
def detectLicensePlate():
|
||||||
yolo_model = YOLO()
|
|
||||||
res = json.loads(request.data)
|
res = json.loads(request.data)
|
||||||
|
|
||||||
# decoded data
|
# decoded data
|
||||||
decoded_data = base64.b64decode(res["imageFile"])
|
decoded_data = base64.b64decode(res["imageFile"])
|
||||||
img_file = open('base64.png', 'wb')
|
img_file = open('API/base64.png', 'wb')
|
||||||
img_file.write(decoded_data)
|
img_file.write(decoded_data)
|
||||||
img_file.close()
|
img_file.close()
|
||||||
image_path = r'base64.png'
|
image_path = r'API/base64.png'
|
||||||
base64_b, texts = yolo_video.detect_license_plate(model=yolo_model, img_path=image_path, i=0)
|
base64_b, texts = yolo_video.detect_license_plate(model=yolo_model, img_path=image_path, i=0)
|
||||||
return jsonify(str(base64_b)), 200
|
return jsonify(str(base64_b)), 200
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=8080)
|
# app.run(threaded=False, host='0.0.0.0', port=8080)
|
||||||
|
|
||||||
|
### to run api just paste following to terminal from root dir of project
|
||||||
|
# export FLASK_APP=API/api.py
|
||||||
|
# flask run --without-threads
|
1
API/model_data/_classes.txt
Normal file
1
API/model_data/_classes.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
licence
|
@ -26,7 +26,7 @@ class YOLO(object):
|
|||||||
_defaults = {
|
_defaults = {
|
||||||
"model_path": 'API/model_data/trained_weights_final.h5',
|
"model_path": 'API/model_data/trained_weights_final.h5',
|
||||||
"anchors_path": 'API/model_data/yolo_anchors.txt',
|
"anchors_path": 'API/model_data/yolo_anchors.txt',
|
||||||
"classes_path": 'API/train/_classes.txt',
|
"classes_path": 'API/model_data/_classes.txt',
|
||||||
"score": 0.3,
|
"score": 0.3,
|
||||||
"iou": 0.45,
|
"iou": 0.45,
|
||||||
"model_image_size": (256,256),#(128, 128),
|
"model_image_size": (256,256),#(128, 128),
|
||||||
|
@ -11,7 +11,7 @@ from keras.layers import BatchNormalization
|
|||||||
from keras.models import Model
|
from keras.models import Model
|
||||||
from keras.regularizers import l2
|
from keras.regularizers import l2
|
||||||
|
|
||||||
from API.yolo3.utils import compose
|
from yolo3.utils import compose
|
||||||
|
|
||||||
|
|
||||||
@wraps(Conv2D)
|
@wraps(Conv2D)
|
||||||
|
Loading…
Reference in New Issue
Block a user