def recognition_digit_image(fname, digit = 100): im = cv2.imread(fname) im = img.change_size_with_size(im, 28, 28) im = img.change_grayscale(im) im = 255. - im input_data = im input_data = input_data.astype(np.float64) input_data = im / im.max() tmp_data = np.reshape(input_data, (28*28, 1)) neuro_obj.test(tmp_data, teach_data) output = neuro_obj.get_output() if digit >=0 and digit <= 9: if neuro_obj.get_max_output_index() == digit : print "judged(success):", neuro_obj.get_max_output_index() else : print "judged(miss) :", neuro_obj.get_max_output_index()
def recognition_digit_image(fname, digit = 100): im = cv2.imread(fname) im = img.change_size_with_size(im, 28, 28) im = img.change_grayscale(im) im = 255 - im input_data = im input_data = input_data.astype(np.float64) input_data = im / im.max() input_data = np.reshape(input_data, (1, 28*28)) neuro_obj.test(input_data, teach_data) output = neuro_obj.get_output() if digit >=0 and digit <= 9: print "judged:", neuro_obj.get_max_output_index(), print ", target order:", np.where(np.fliplr(np.argsort(output)) == digit)[1] + 1, print ", order array:", np.fliplr(np.argsort(output)) else: print "judged:", neuro_obj.get_max_output_index(), print ", order array:", np.fliplr(np.argsort(output)) cv2.imshow("input_data", im) cv2.waitKey(0) cv2.destroyAllWindows()