Skip to content
Snippets Groups Projects
Commit 4269f2ab authored by razvan841's avatar razvan841 Committed by Niccolo de Vries
Browse files

added debugging

parent 838d3459
Branches
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@ import numpy as np
from tensorflow.keras.models import load_model # type: ignore
import os
DEBUGGING = True
def extract_patches(image):
height, width, _ = image.shape
square_height = height // 3
......@@ -31,6 +33,20 @@ def predict_colors(model, image):
predicted_colors = [np.argmax(pred) for pred in predictions]
return predicted_colors
def indices_to_colors(indices):
"""
Converts an array of indices into a list of color names.
Args:
indices (list of int): List of color indices predicted by the model.
Returns:
list of str: List of color names corresponding to the indices.
"""
color_map = {0: 'white', 1: 'yellow', 2: 'red', 3: 'blue', 4: 'green', 5: 'orange'}
return [color_map[idx] for idx in indices]
def main():
model_path = "rubiks_cube_model.h5"
if not os.path.exists(model_path):
......@@ -58,9 +74,25 @@ def main():
# Wait for the user to press 'c' to capture or 'q' to quit
key = cv2.waitKey(1) & 0xFF
if key == ord('c'):
print("Processing captured image...")
predicted_colors = predict_colors(model, frame)
print("Predicted Colors:", predicted_colors)
# Show the captured image to the user
while True:
cv2.imshow("Captured Image - Press 'y' to proceed or 'r' to retake", frame)
key_confirm = cv2.waitKey(0) & 0xFF
if key_confirm == ord('y'):
print("Processing captured image...")
predicted_colors = predict_colors(model, frame)
colors = None
if(DEBUGGING):
colors = indices_to_colors(predicted_colors)
print(colors)
else:
print("Predicted Colors:", predicted_colors)
break # Exit confirmation loop and return to live feed
elif key_confirm == ord('r'):
print("Retaking the picture...")
break # Retake the picture
elif key == ord('q'):
print("Exiting...")
break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment