Exemplo n.º 1
0
args = ([], X, y, 0.0)
"""
print "T:"
print(type(t))
print(str(t))
print(t.shape)
print "X:"
print(type(X))
print(str(X))
print(X.shape)
print "y:"
print(type(y))
print(str(y))
print(y.shape)
"""
res1 = optimize.fmin_cg(NN2.getJ, t, fprime=NN2.getGrad, args=args, maxiter=1000)#, gtol=0.0000000005)
#print 'res1 = ', res1
out = NN2.runNet(res1, [], X, y)
s = str(get_class_match(out[0]))
for i in out[1:len(out)]:
   s = s + ", "+str(get_class_match(i))
print s
NN2.save_theta('625_39_ocr_theta.txt', res1)
print "Theta saved to 625_39_ocr_theta."






Exemplo n.º 2
0
sys.path.append("image_processing/")
import capture as cap

def imax(xs):
   m = max(xs)
   return [i for i, j in enumerate(xs) if j == m]

def get_class_match(xs):
   classes     = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "!", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", ".", "q", "?", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
   return classes[imax(xs)[0]]

theta = np.array(NN2.load_theta('625_39_ocr_theta.txt'))

img_path = sys.argv[1]
bimg = Image.open(img_path)
tup = cap.collectCharacters2(bimg)
tup.sort(key=lambda tup: tup[0][0])
imgs = [y[1] for y in tup]
s = ""
for img in imgs:
#   print str(img)
   X = np.array(list(img.getdata()))
#   print str(X.shape)
   s = s + get_class_match(NN2.runNet(theta,[625,39],X)[0])

print s
#img = Image.open('images/times_new_roman_characters/times_s.png')
#X = np.array(list(img.getdata()))
#print get_class_match(NN2.runNet(theta,[625,39],X)[0])