Skip to content
Snippets Groups Projects
Commit a4d04f4e authored by michael.divia's avatar michael.divia
Browse files

Show image on screen

parent e642f085
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import cv2 ...@@ -2,6 +2,7 @@ import cv2
import numpy as np import numpy as np
import json import json
import argparse import argparse
import os
from hailo_platform.pyhailort import HailoRT from hailo_platform.pyhailort import HailoRT
# --- Argparse --- # --- Argparse ---
...@@ -47,13 +48,24 @@ if not ret: ...@@ -47,13 +48,24 @@ if not ret:
print("-- Failed to capture image") print("-- Failed to capture image")
exit(1) 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 --- # --- Preprocess image ---
image = cv2.resize(frame, input_shape) image = cv2.resize(frame, input_shape)
image = image.astype(np.float32) 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 -= [123.68, 116.779, 103.939]
# image /= 255.0 # only if your model was trained with [0,1] normalization
# NHWC → NCHW # NHWC → NCHW
image = np.transpose(image, (2, 0, 1)) # (H, W, C) → (C, H, W) 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 ...@@ -67,4 +79,4 @@ with HailoRT.VirtualStreams(input_info, output_info, network_group) as (input_vs
# --- Postprocess --- # --- Postprocess ---
predicted_idx = int(np.argmax(output_data)) predicted_idx = int(np.argmax(output_data))
predicted_name = class_names[predicted_idx] predicted_name = class_names[predicted_idx]
print(f"🎯 Predicted Pokémon: {predicted_name}") print(f"-- Predicted Pokémon: {predicted_name}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment