From a4d04f4ebc88f41692f6a9b62cd407757bacb391 Mon Sep 17 00:00:00 2001
From: "michael.divia" <michael.divia@etu.hesge.ch>
Date: Wed, 9 Apr 2025 20:39:04 +0200
Subject: [PATCH] Show image on screen

---
 python/pokedex_rpi.py | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/python/pokedex_rpi.py b/python/pokedex_rpi.py
index 52a17af..449a764 100644
--- a/python/pokedex_rpi.py
+++ b/python/pokedex_rpi.py
@@ -2,6 +2,7 @@ import cv2
 import numpy as np
 import json
 import argparse
+import os
 from hailo_platform.pyhailort import HailoRT
 
 # --- Argparse ---
@@ -47,13 +48,24 @@ if not ret:
     print("-- Failed to capture image")
     exit(1)
 
+# --- Try to display the captured image ---
+try:
+    cv2.imshow("Captured Image", frame)
+    print("-- Press any key to continue...")
+    cv2.waitKey(0)
+    cv2.destroyAllWindows()
+except cv2.error as e:
+    print("-- GUI display failed, saving and showing with feh instead...")
+    output_path = "/tmp/captured.png"
+    cv2.imwrite(output_path, frame)
+    os.system(f"feh --fullscreen {output_path}")
+
 # --- Preprocess image ---
 image = cv2.resize(frame, input_shape)
 image = image.astype(np.float32)
 
-# Standard Hailo normalization (if your model expects ImageNet style)
+# Standard Hailo normalization
 image -= [123.68, 116.779, 103.939]
-# image /= 255.0  # only if your model was trained with [0,1] normalization
 
 # NHWC → NCHW
 image = np.transpose(image, (2, 0, 1))   # (H, W, C) → (C, H, W)
@@ -67,4 +79,4 @@ with HailoRT.VirtualStreams(input_info, output_info, network_group) as (input_vs
 # --- Postprocess ---
 predicted_idx = int(np.argmax(output_data))
 predicted_name = class_names[predicted_idx]
-print(f"🎯 Predicted Pokémon: {predicted_name}")
+print(f"-- Predicted Pokémon: {predicted_name}")
-- 
GitLab