fix yolo image boxes

This commit is contained in:
2025-01-06 16:11:03 +01:00
parent 228c508012
commit 7d1b878c30

View File

@@ -28,7 +28,7 @@ def on_message(client, userdata, message):
yolo_results = [] yolo_results = []
for result in results: for result in results:
for box in result.boxes: for box in result.boxes:
class_id = int(box.cls.item()) # Convert to integer class_id = int(box.cls.item()) # Convert to integer
class_name = yolo_classes[class_id] class_name = yolo_classes[class_id]
yolo_results.append({ yolo_results.append({
"class": class_name, "class": class_name,
@@ -36,7 +36,7 @@ def on_message(client, userdata, message):
"bbox": box.xyxy.tolist() "bbox": box.xyxy.tolist()
}) })
# Draw bounding box on the image # Draw bounding box on the image
x1, y1, x2, y2 = map(int, box.xyxy) x1, y1, x2, y2 = map(int, box.xyxy[0])
cv2.rectangle(latest_image, (x1, y1), (x2, y2), (0, 255, 0), 2) cv2.rectangle(latest_image, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(latest_image, f"{class_name} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2) cv2.putText(latest_image, f"{class_name} {box.conf.item():.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)