From 2a00c812fb0f94a08d2a1d5a5b3770755c4f94f7 Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Fri, 25 May 2018 14:37:32 +1000 Subject: [PATCH] Add some steps --- mini_proj/test_nn.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/mini_proj/test_nn.py b/mini_proj/test_nn.py index 9acdc4e..f33f837 100644 --- a/mini_proj/test_nn.py +++ b/mini_proj/test_nn.py @@ -3,6 +3,7 @@ from keras.models import Model, load_model from keras.utils import to_categorical import cv2 from skimage import color, exposure +from _cutter import image_cut def man_result_check(): pred_y = np.load("predicted_results.npy") @@ -14,7 +15,7 @@ def man_result_check(): z = 0 for i in range(0, len(test_y)): print(pred_y[i], test_y[i], file=f) - # Calculates correct predictions + # Calculates correct predictions if pred_y[i][0] == test_y[i][0]: z+=1 @@ -25,7 +26,7 @@ def man_result_check(): Purpose:Loads a trained neural network model (using Keras) to classify an image Input: path/to/trained_model image [or] path/to/image [if from_file=True] -Returns:Boolean variable +Returns:Boolean variable ''' def is_Wally(trained_model_path, image, from_file=False): if from_file: @@ -50,5 +51,22 @@ def is_Wally(trained_model_path, image, from_file=False): # Mark Wally image somehow (colour the border) # Stitch original image back together +if __name__ == '__main__': + # Read image + image = cv2.imread("10.jpg") + # Split image + cuts = image_cut(image, 64, 64) + for i in len(cuts): + # Transform block + hsv = color.rgb2hsv(cuts[i]) + hsv[:, :, 2] = exposure.equalize_hist(hsv[:, :, 2]) + block = color.hsv2rgb(hsv) + block = np.rollaxis(block, -1) + if is_Wally("Waldo.h5", block): + # Border block + cuts[i] = cv2.copyMakeBorder(cuts[i],5,5,5,5,cv2.BORDER_CONSTANT,value=RED) -is_Wally("Waldo.h5", image) \ No newline at end of file + # Stitch image TODO! + # Show image + cv.imshow('Image', image) + cv.waitKey(0)