No empty logs and fixes some errors

This commit is contained in:
2025-06-18 15:05:47 +02:00
parent fbdfe86eee
commit d074c9bf27
7 changed files with 35 additions and 21 deletions

View File

@@ -20,11 +20,15 @@ async def process_image(image: bytes) -> str:
if r.boxes:
for box in r.boxes:
cls_name = r.names[int(box.cls[0])]
if cls_name == "car":
if cls_name in ["car", "truck"]:
x1, y1, x2, y2 = map(int, box.xyxy[0])
size = (x2 - x1) ** 2 + (y2 - y1) ** 2
cars.append((size, (x1, y1, x2, y2)))
else:
return ""
if cars == []:
return ""
# Get the biggest car box
size, corners = max(cars, key=lambda x: x[0])
@@ -45,5 +49,7 @@ async def process_image(image: bytes) -> str:
lp_np = np.array(object=lp_img)
result = ocr_reader.readtext(image=lp_np)
print(result)
else:
return ""
return str(result[0][1]) # type: ignore

View File

@@ -17,13 +17,14 @@ def data():
application.last_image.seek(0)
application.last_image = io.BytesIO(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()
allowed = False
if np != "":
# 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(

View File

@@ -23,8 +23,10 @@ def dashboard():
.limit(50)
.all()
)
form = npForm()
return render_template("dashboard.html", plates=Plates, logs=logs, form=form)
form = npForm()
return render_template(
"dashboard.html", plates=Plates, logs=logs, form=form
)
@dash_blueprint.route("/add", methods=["GET", "POST"])