Sped up ANPR

Sped up ANPR by only creating one ANPR instance, rather than initializing a new one every function call.
This commit is contained in:
2025-04-25 07:55:49 +02:00
parent 8fb271ee72
commit 5e4b1acca0
2 changed files with 3 additions and 3 deletions

Binary file not shown.

View File

@@ -12,6 +12,7 @@ torch.serialization.add_safe_globals( # type: ignore
{"DetectionModel": DetectionModel} # type: ignore {"DetectionModel": DetectionModel} # type: ignore
) )
anpr = ANPR()
# Saving images locally # Saving images locally
UPLOAD_FOLDER = "uploads" UPLOAD_FOLDER = "uploads"
@@ -32,7 +33,7 @@ def data():
with open("image.jpg", "wb") as f: with open("image.jpg", "wb") as f:
f.write(data) f.write(data)
status = asyncio.run(process_image("image.jpg")) status = asyncio.run(process_image(file="image.jpg", anpr=anpr))
return jsonify( return jsonify(
{ {
"message": "Image sent succesfully", "message": "Image sent succesfully",
@@ -41,9 +42,8 @@ def data():
) )
async def process_image(file: str) -> bool: async def process_image(file: str, anpr: ANPR) -> bool:
print("Processing image") print("Processing image")
anpr = ANPR()
anpr_info = await anpr.detect(file) # type: ignore anpr_info = await anpr.detect(file) # type: ignore
number_plate = anpr_info["plate_number"] number_plate = anpr_info["plate_number"]
if number_plate: if number_plate: