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"])

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 872 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -15,19 +15,23 @@ good_pin = Pin(15, Pin.OUT)
bad_pin = Pin(14, Pin.OUT)
# Send the POST request with the raw image data as the body
url = f'http://{config.server}:{config.port}/{config.data_path}'
url = f"http://{config.server}:{config.port}/{config.data_path}"
spi = SPI(0,sck=Pin(18), miso=Pin(16), mosi=Pin(19), baudrate=8000000) # Pins for the Raspberry Pi Pico
spi = SPI(
0, sck=Pin(18), miso=Pin(16), mosi=Pin(19), baudrate=8000000
) # Pins for the Raspberry Pi Pico
cs = Pin(17, Pin.OUT)
cam = Camera(spi, cs, debug_text_enabled=True)
headers = {"Content-Type": "image/jpeg"}
addr = socket.getaddrinfo(config.server,config.port)[0][-1]
addr = socket.getaddrinfo(config.server, config.port)[0][-1]
def send_image(image_file_path):
cam.capture_jpg()
with open(image_file_path, 'wb') as f:
with open(image_file_path, "wb") as f:
f.write(b"")
cam.save_JPG(image_file_path)
with open(image_file_path, 'rb') as f:
with open(image_file_path, "rb") as f:
s = socket.socket()
s.connect(addr)
# Send HTTP headers
@@ -36,9 +40,9 @@ def send_image(image_file_path):
s.send(b"Transfer-Encoding: chunked\r\n")
s.send(b"Content-Type: application/octet-stream\r\n")
s.send(b"\r\n")
chunk_size = 512
while True:
chunk = f.read(chunk_size)
if not chunk:
@@ -54,16 +58,17 @@ def send_image(image_file_path):
# Final chunk to end the stream
s.send(b"0\r\n\r\n")
s.close()
return
while connection.isconnected():
good_pin.low()
bad_pin.low()
wait_pin.high()
#if random.choice([True, False]):
# if random.choice([True, False]):
# response = send_image("1234.jpg")
#else:
# else:
# response = send_image("car2.jpg")
response = send_image("image.jpg")
print(response)
@@ -73,4 +78,4 @@ while connection.isconnected():
good_pin.high()
else:
bad_pin.high()
sleep(5)
sleep(5)

BIN
received_image.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB