From 962ffb8f13a5ffe21f020b7dc2abcd600edc5907 Mon Sep 17 00:00:00 2001
From: "michael.divia" <michael.divia@etu.hesge.ch>
Date: Wed, 9 Apr 2025 21:24:00 +0200
Subject: [PATCH] Error on size of image

---
 python/pokedex_rpi.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/python/pokedex_rpi.py b/python/pokedex_rpi.py
index a14d342..2f87792 100644
--- a/python/pokedex_rpi.py
+++ b/python/pokedex_rpi.py
@@ -28,20 +28,28 @@ with open(json_path, "r") as f:
 # --- Inference ---
 with Hailo(hef_path) as hailo:
     model_h, model_w, _ = hailo.get_input_shape()
+    print(f"-- Hailo model input size: {model_w}x{model_h}")
 
-    # Initialize camera and configure MAIN output only (no preview)
     picam2 = Picamera2()
+
+    # Use *raw* capture configuration with correct size
     config = picam2.create_still_configuration(
         main={"size": (model_w, model_h), "format": "RGB888"},
-        display=None  # Disable preview stream to avoid tiny resolution
+        lores=None,
+        display=None
     )
     picam2.configure(config)
     picam2.start()
 
     print("-- Capturing image...")
     frame = picam2.capture_array()
+    print(f"-- Captured frame shape: {frame.shape}")
+
+    if frame.shape[0] != model_h or frame.shape[1] != model_w:
+        print("-- Frame shape doesn't match model input size. Aborting.")
+        exit(1)
 
-    # Optional: Show the captured image
+    # Optional: display image
     try:
         cv2.imshow("Captured Image", frame)
         print("-- Press any key to continue...")
@@ -58,4 +66,4 @@ with Hailo(hef_path) as hailo:
 
     predicted_idx = int(np.argmax(inference_results))
     predicted_name = class_names[predicted_idx]
-    print(f"-- Predicted Pokémon: {predicted_name}")
\ No newline at end of file
+    print(f"-- Predicted Pokémon: {predicted_name}")
-- 
GitLab