Пример #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
def analyze_digit_SVM(img):
    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 = 8, 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")
Пример #3
0
        Digit Segmentation and Classification Using 
        MLP and OpenCV on GoogleStreetView Data Base

        Created by:  Chenxing Ouyang & Jiali Xie

"""
import sys
import cv2
import numpy as np
from pylab import imread, imshow, imsave, figure, show, subplot, plot, scatter, title
import ocr
import multilayerPerceptron as mlp

print(__doc__)

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


print ("Preprocessing Image, Cropping Digits Into 28 X 28 Image Matrices\n")
#  save_digit_to_binary_img_as_mnist(imgName, saveToFile = True, imgSize = 100, boundingRectMinSize = 5)
cropped_img_for_show, cropped_digits = ocr.save_digit_to_binary_img_as_mnist("../pics/12.png",saveToFile = True)

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


print ("Building Multilayer Perceptron Network From Trained Model\n")
mlp_classifier = mlp.build_classifier('../trainedResult/model.npz')

# input_img = imread('../pics/cropped/0.png')
# print mlp.predict(input_img, mlp_classifier)
Пример #4
0
        Digit Segmentation and Classification Using 
        MLP and OpenCV on GoogleStreetView Data Base

        Created by:  Chenxing Ouyang & Jiali Xie

"""
import sys
import cv2
import numpy as np
from pylab import imread, imshow, imsave, figure, show, subplot, plot, scatter, title
import ocr
import multilayerPerceptron as mlp

print(__doc__)

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

print("Preprocessing Image, Cropping Digits Into 28 X 28 Image Matrices\n")
#  save_digit_to_binary_img_as_mnist(imgName, saveToFile = True, imgSize     = 100, boundingRectMinSize = 5)
cropped_img_to_show, cropped_thresh_to_Show, cropped_digits = ocr.save_digit_to_binary_img_as_mnist(
    "../pics/print.png", dim=28, imgSize=100, saveToFile=True)

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

print("Building Multilayer Perceptron Network From Trained Model\n")
mlp_classifier = mlp.build_classifier('../trainedResult/model.npz')

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