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: if r.boxes:
for box in r.boxes: for box in r.boxes:
cls_name = r.names[int(box.cls[0])] 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]) x1, y1, x2, y2 = map(int, box.xyxy[0])
size = (x2 - x1) ** 2 + (y2 - y1) ** 2 size = (x2 - x1) ** 2 + (y2 - y1) ** 2
cars.append((size, (x1, y1, x2, y2))) cars.append((size, (x1, y1, x2, y2)))
else:
return ""
if cars == []:
return ""
# Get the biggest car box # Get the biggest car box
size, corners = max(cars, key=lambda x: x[0]) 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) lp_np = np.array(object=lp_img)
result = ocr_reader.readtext(image=lp_np) result = ocr_reader.readtext(image=lp_np)
print(result) print(result)
else:
return ""
return str(result[0][1]) # type: ignore return str(result[0][1]) # type: ignore

View File

@@ -17,7 +17,8 @@ def data():
application.last_image.seek(0) application.last_image.seek(0)
application.last_image = io.BytesIO(request.data) application.last_image = io.BytesIO(request.data)
np = asyncio.run(process_image(image=data)) np = asyncio.run(process_image(image=data))
allowed = False
if np != "":
# Check if the found plate is allowed to exit # Check if the found plate is allowed to exit
allowed = AllowedPlate.query.filter_by(plate=np).first() is not None allowed = AllowedPlate.query.filter_by(plate=np).first() is not None
db.session.add( # Log the found numberplate and status db.session.add( # Log the found numberplate and status

View File

@@ -24,7 +24,9 @@ def dashboard():
.all() .all()
) )
form = npForm() form = npForm()
return render_template("dashboard.html", plates=Plates, logs=logs, form=form) return render_template(
"dashboard.html", plates=Plates, logs=logs, form=form
)
@dash_blueprint.route("/add", methods=["GET", "POST"]) @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) bad_pin = Pin(14, Pin.OUT)
# Send the POST request with the raw image data as the body # 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) cs = Pin(17, Pin.OUT)
cam = Camera(spi, cs, debug_text_enabled=True) cam = Camera(spi, cs, debug_text_enabled=True)
headers = {"Content-Type": "image/jpeg"} 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): def send_image(image_file_path):
cam.capture_jpg() cam.capture_jpg()
with open(image_file_path, 'wb') as f: with open(image_file_path, "wb") as f:
f.write(b"") f.write(b"")
cam.save_JPG(image_file_path) 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 = socket.socket()
s.connect(addr) s.connect(addr)
# Send HTTP headers # Send HTTP headers
@@ -57,13 +61,14 @@ def send_image(image_file_path):
return return
while connection.isconnected(): while connection.isconnected():
good_pin.low() good_pin.low()
bad_pin.low() bad_pin.low()
wait_pin.high() wait_pin.high()
#if random.choice([True, False]): # if random.choice([True, False]):
# response = send_image("1234.jpg") # response = send_image("1234.jpg")
#else: # else:
# response = send_image("car2.jpg") # response = send_image("car2.jpg")
response = send_image("image.jpg") response = send_image("image.jpg")
print(response) print(response)

BIN
received_image.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB