From 20d6d8799db5ac8106ddc107c37bb9ba6c91bed9 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Mon, 6 Jan 2025 15:45:29 +0100 Subject: [PATCH] attempt to show name next to image box --- src/Python/flask/web/app.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index 872da43..0097c45 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -9,6 +9,11 @@ app = Flask(__name__) # Load a model model = YOLO("yolo11n.pt") # pretrained YOLO11n model +#from: https://medium.com/@Mert.A/how-to-segment-objects-with-yolov11-68593eb49fa8 +yolo_classes = list(model.names.values()) +classes_ids = [yolo_classes.index(clas) for clas in yolo_classes] + + kobuki_message = "" latest_image = None yolo_results = [] @@ -26,14 +31,14 @@ def on_message(client, userdata, message): for result in results: for box in result.boxes: yolo_results.append({ - "class": box.cls.item(), + "class": yolo_classes, "confidence": box.conf.item(), "bbox": box.xyxy.tolist() }) # Draw bounding box on the image x1, y1, x2, y2 = map(int, box.xyxy[0]) cv2.rectangle(latest_image, (x1, y1), (x2, y2), (0, 255, 0), 2) - cv2.putText(latest_image, f"{box.cls.item()} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2) + cv2.putText(latest_image, f"{yolo_classes} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2) # Create an MQTT client instance mqtt_client = mqtt.Client()