mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 11:19:57 +00:00
refactoring + execution time
This commit is contained in:
BIN
application/api/__pycache__/image_processing.cpython-313.pyc
Normal file
BIN
application/api/__pycache__/image_processing.cpython-313.pyc
Normal file
Binary file not shown.
BIN
application/api/__pycache__/views.cpython-313.pyc
Normal file
BIN
application/api/__pycache__/views.cpython-313.pyc
Normal file
Binary file not shown.
16
application/api/image_processing.py
Normal file
16
application/api/image_processing.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from application import anpr
|
||||
import io
|
||||
|
||||
|
||||
async def process_image(image: bytes) -> str:
|
||||
print("Saving file to memory")
|
||||
image_file = io.BytesIO(image)
|
||||
|
||||
print("Processing image")
|
||||
anpr_info = await anpr.detect(image_file) # type: ignore
|
||||
|
||||
if anpr_info is None:
|
||||
print("Something went wrong with ANPR")
|
||||
return ""
|
||||
|
||||
return str(anpr_info["plate_number"])
|
||||
@@ -1,3 +1,30 @@
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, request, jsonify
|
||||
from application import db
|
||||
from application.models import AllowedPlate, LoggedItem
|
||||
from application.api.image_processing import process_image
|
||||
from datetime import datetime
|
||||
import asyncio
|
||||
|
||||
api_blueprint = Blueprint('api', )
|
||||
api_blueprint = Blueprint("api", __name__, template_folder="templates")
|
||||
|
||||
|
||||
# API to process vehicle
|
||||
@api_blueprint.route("/api", methods=["POST"])
|
||||
def data():
|
||||
data = request.data
|
||||
np = asyncio.run(process_image(image=data))
|
||||
|
||||
# Check if the found plate is allowed to exit
|
||||
allowed = AllowedPlate.query.filter_by(plate=np).first() is not None
|
||||
db.session.add( # Log the found numberplate and status
|
||||
LoggedItem(plate=np, allowed=allowed, datetime=datetime.now())
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
# Return decision to Pico
|
||||
return jsonify(
|
||||
{
|
||||
"message": "Image sent succesfully",
|
||||
"status": allowed,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user