コード例 #1
0
def analyze_digit_MLP(img):
    """ Takes in an image matrix, crops out the digits and outputs it to file """

    ocr.delete_files("../pics/cropped/")

    print ("Preprocessing Image, Cropping Digits Into 28 X 28 Image Matrices\n")
    cropped_img_to_show, cropped_thresh_to_Show, cropped_digits = ocr.save_digit_to_binary_img_as_mnist(img, dim = 28, saveToFile = True, imgSize = frame_new_dim)

    print ("Image Preprocessing Done, %d Potential Digits Were Cropped Out\n" % len(cropped_digits))

    print ("Predicting Results\n")
    print ("Image    Digit     probability")

    index = 0
    for input_digit in cropped_digits:
        path = "../pics/cropped/" + str(index) + ".png"
        input_digit = imread(path)
        digit, probability = mlp.predict(input_digit, mlp_classifier)
        print ("%d.png      %d         %f" % (index, digit, probability))
        index += 1

    new_dim = (SCALE_FACTOR * img.shape[1]/2, SCALE_FACTOR * img.shape[0]/2)
    cropped_img_to_show = cv2.resize(cropped_img_to_show, new_dim)
    cropped_thresh_to_Show = cv2.resize(cropped_thresh_to_Show, new_dim)
    cv2.imshow('handWriting Capture Cropped Image', cropped_img_to_show)
    cv2.imshow('handWriting Capture Cropped Thresh', cropped_thresh_to_Show)
コード例 #2
0
ファイル: main.py プロジェクト: avanisho/OCR
# input_img = imread('../pics/cropped/0.png')
# print mlp.predict(input_img, mlp_classifier)

print ("Predicting Results\n")
print ("Image    Digit     probability")

# Loading from matrix
# index = 0
# for input_digit in cropped_digits:
#     digit, probability = mlp.predict(input_digit, mlp_classifier)
#     print ("%d.png      %d         %f" % (index, digit, probability))
#     index += 1

# Loading from Image
index = 0
for input_digit in cropped_digits:
    path = "../pics/cropped/" + str(index) + ".png"
    input_digit = imread(path)
    digit, probability = mlp.predict(input_digit, mlp_classifier)
    print ("%d.png      %d         %f" % (index, digit, probability))
    index += 1



figure(1)
title("handWriting")
cv2.imwrite("../pics/cropped/cvPic3.png", cropped_img_for_show)
subplot(111)
imshow(cropped_img_for_show)
show()
コード例 #3
0
import numpy as np
import theano
import theano.tensor as T

import lasagne
import matplotlib
import matplotlib.cm as cm
import matplotlib.pyplot as plt
from pylab import imread, imshow, imsave, figure, show, subplot, plot, scatter, title
import multilayerPerceptron as mlp


f_output = mlp.build_classifier('../trainedResult/model.npz')

input_img = imread('../pics/cropped/20.png')

print mlp.predict(input_img, f_output)


plt.subplot(211)
plt.imshow(input_img, cmap=cm.binary)
instance = input_img.reshape(-1, 1, 28, 28)
pred = f_output(instance)
N = pred.shape[1]
plt.subplot(212)
#result with probability
plt.bar(range(N), pred.ravel())

plt.show()

コード例 #4
0
ファイル: cvTest2.py プロジェクト: dyther/OCR
mlp_classifier = mlp.build_classifier('../trainedResult/model.npz')

# input_img = imread('../pics/cropped/0.png')
# print mlp.predict(input_img, mlp_classifier)

print("Predicting Results\n")
print("Image    Digit     probability")

# Loading from matrix
# index = 0
# for input_digit in cropped_digits:
#     digit, probability = mlp.predict(input_digit, mlp_classifier)
#     print ("%d.png      %d         %f" % (index, digit, probability))
#     index += 1

# Loading from Image
index = 0
for input_digit in cropped_digits:
    path = "../pics/cropped/" + str(index) + ".png"
    input_digit = imread(path)
    digit, probability = mlp.predict(input_digit, mlp_classifier)
    print("%d.png      %d         %f" % (index, digit, probability))
    index += 1

figure(1)
title("handWriting")
cv2.imwrite("../pics/cropped/cvPic3.png", cropped_img_to_show)
subplot(111)
imshow(cropped_img_to_show)
show()