go and python version. Both works fine
BIN
pythonVersion/images/blank.png
Normal file
|
After Width: | Height: | Size: 129 B |
BIN
pythonVersion/images/dot.png
Normal file
|
After Width: | Height: | Size: 138 B |
BIN
pythonVersion/images/dotndot.png
Normal file
|
After Width: | Height: | Size: 140 B |
BIN
pythonVersion/images/numbers/0.1.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/0.2.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
pythonVersion/images/numbers/0.3.png
Normal file
|
After Width: | Height: | Size: 178 B |
BIN
pythonVersion/images/numbers/0.4.png
Normal file
|
After Width: | Height: | Size: 156 B |
BIN
pythonVersion/images/numbers/0.5.png
Normal file
|
After Width: | Height: | Size: 167 B |
BIN
pythonVersion/images/numbers/0.6.png
Normal file
|
After Width: | Height: | Size: 172 B |
BIN
pythonVersion/images/numbers/0.7.png
Normal file
|
After Width: | Height: | Size: 165 B |
BIN
pythonVersion/images/numbers/0.8.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/0.9.png
Normal file
|
After Width: | Height: | Size: 167 B |
BIN
pythonVersion/images/numbers/1.1.png
Normal file
|
After Width: | Height: | Size: 141 B |
BIN
pythonVersion/images/numbers/1.2.png
Normal file
|
After Width: | Height: | Size: 135 B |
BIN
pythonVersion/images/numbers/1.3.png
Normal file
|
After Width: | Height: | Size: 136 B |
BIN
pythonVersion/images/numbers/1.4.png
Normal file
|
After Width: | Height: | Size: 150 B |
BIN
pythonVersion/images/numbers/1.5.png
Normal file
|
After Width: | Height: | Size: 147 B |
BIN
pythonVersion/images/numbers/1.6.png
Normal file
|
After Width: | Height: | Size: 156 B |
BIN
pythonVersion/images/numbers/1.7.png
Normal file
|
After Width: | Height: | Size: 156 B |
BIN
pythonVersion/images/numbers/1.8.png
Normal file
|
After Width: | Height: | Size: 154 B |
BIN
pythonVersion/images/numbers/1.9.png
Normal file
|
After Width: | Height: | Size: 171 B |
BIN
pythonVersion/images/numbers/2.1.png
Normal file
|
After Width: | Height: | Size: 177 B |
BIN
pythonVersion/images/numbers/2.2.png
Normal file
|
After Width: | Height: | Size: 178 B |
BIN
pythonVersion/images/numbers/2.3.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
pythonVersion/images/numbers/2.4.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
pythonVersion/images/numbers/2.5.png
Normal file
|
After Width: | Height: | Size: 173 B |
BIN
pythonVersion/images/numbers/2.6.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
pythonVersion/images/numbers/2.7.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
pythonVersion/images/numbers/2.8.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
pythonVersion/images/numbers/2.9.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
pythonVersion/images/numbers/3.1.png
Normal file
|
After Width: | Height: | Size: 166 B |
BIN
pythonVersion/images/numbers/3.2.png
Normal file
|
After Width: | Height: | Size: 160 B |
BIN
pythonVersion/images/numbers/3.3.png
Normal file
|
After Width: | Height: | Size: 165 B |
BIN
pythonVersion/images/numbers/3.4.png
Normal file
|
After Width: | Height: | Size: 166 B |
BIN
pythonVersion/images/numbers/3.5.png
Normal file
|
After Width: | Height: | Size: 174 B |
BIN
pythonVersion/images/numbers/3.6.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
pythonVersion/images/numbers/3.7.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
pythonVersion/images/numbers/3.8.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
pythonVersion/images/numbers/3.9.png
Normal file
|
After Width: | Height: | Size: 173 B |
BIN
pythonVersion/images/numbers/4.1.png
Normal file
|
After Width: | Height: | Size: 152 B |
BIN
pythonVersion/images/numbers/4.2.png
Normal file
|
After Width: | Height: | Size: 156 B |
BIN
pythonVersion/images/numbers/4.3.png
Normal file
|
After Width: | Height: | Size: 159 B |
BIN
pythonVersion/images/numbers/4.4.png
Normal file
|
After Width: | Height: | Size: 157 B |
BIN
pythonVersion/images/numbers/4.5.png
Normal file
|
After Width: | Height: | Size: 150 B |
BIN
pythonVersion/images/numbers/4.6.png
Normal file
|
After Width: | Height: | Size: 154 B |
BIN
pythonVersion/images/numbers/4.7.png
Normal file
|
After Width: | Height: | Size: 151 B |
BIN
pythonVersion/images/numbers/4.8.png
Normal file
|
After Width: | Height: | Size: 151 B |
BIN
pythonVersion/images/numbers/4.9.png
Normal file
|
After Width: | Height: | Size: 155 B |
BIN
pythonVersion/images/numbers/5.1.png
Normal file
|
After Width: | Height: | Size: 169 B |
BIN
pythonVersion/images/numbers/5.2.png
Normal file
|
After Width: | Height: | Size: 158 B |
BIN
pythonVersion/images/numbers/5.3.png
Normal file
|
After Width: | Height: | Size: 174 B |
BIN
pythonVersion/images/numbers/5.4.png
Normal file
|
After Width: | Height: | Size: 171 B |
BIN
pythonVersion/images/numbers/5.5.png
Normal file
|
After Width: | Height: | Size: 167 B |
BIN
pythonVersion/images/numbers/5.6.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/5.7.png
Normal file
|
After Width: | Height: | Size: 159 B |
BIN
pythonVersion/images/numbers/5.8.png
Normal file
|
After Width: | Height: | Size: 158 B |
BIN
pythonVersion/images/numbers/5.9.png
Normal file
|
After Width: | Height: | Size: 169 B |
BIN
pythonVersion/images/numbers/6.1.png
Normal file
|
After Width: | Height: | Size: 180 B |
BIN
pythonVersion/images/numbers/6.2.png
Normal file
|
After Width: | Height: | Size: 175 B |
BIN
pythonVersion/images/numbers/6.3.png
Normal file
|
After Width: | Height: | Size: 180 B |
BIN
pythonVersion/images/numbers/6.4.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
pythonVersion/images/numbers/6.5.png
Normal file
|
After Width: | Height: | Size: 178 B |
BIN
pythonVersion/images/numbers/6.6.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
pythonVersion/images/numbers/6.7.png
Normal file
|
After Width: | Height: | Size: 174 B |
BIN
pythonVersion/images/numbers/6.8.png
Normal file
|
After Width: | Height: | Size: 170 B |
BIN
pythonVersion/images/numbers/6.9.png
Normal file
|
After Width: | Height: | Size: 170 B |
BIN
pythonVersion/images/numbers/7.1.png
Normal file
|
After Width: | Height: | Size: 158 B |
BIN
pythonVersion/images/numbers/7.2.png
Normal file
|
After Width: | Height: | Size: 165 B |
BIN
pythonVersion/images/numbers/7.3.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/7.4.png
Normal file
|
After Width: | Height: | Size: 163 B |
BIN
pythonVersion/images/numbers/7.5.png
Normal file
|
After Width: | Height: | Size: 164 B |
BIN
pythonVersion/images/numbers/7.6.png
Normal file
|
After Width: | Height: | Size: 163 B |
BIN
pythonVersion/images/numbers/7.7.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/7.8.png
Normal file
|
After Width: | Height: | Size: 162 B |
BIN
pythonVersion/images/numbers/7.9.png
Normal file
|
After Width: | Height: | Size: 163 B |
BIN
pythonVersion/images/numbers/8.1.png
Normal file
|
After Width: | Height: | Size: 151 B |
BIN
pythonVersion/images/numbers/8.2.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/8.3.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/8.4.png
Normal file
|
After Width: | Height: | Size: 177 B |
BIN
pythonVersion/images/numbers/8.5.png
Normal file
|
After Width: | Height: | Size: 153 B |
BIN
pythonVersion/images/numbers/8.6.png
Normal file
|
After Width: | Height: | Size: 153 B |
BIN
pythonVersion/images/numbers/8.7.png
Normal file
|
After Width: | Height: | Size: 148 B |
BIN
pythonVersion/images/numbers/8.8.png
Normal file
|
After Width: | Height: | Size: 150 B |
BIN
pythonVersion/images/numbers/8.9.png
Normal file
|
After Width: | Height: | Size: 169 B |
BIN
pythonVersion/images/numbers/9.1.png
Normal file
|
After Width: | Height: | Size: 168 B |
BIN
pythonVersion/images/numbers/9.2.png
Normal file
|
After Width: | Height: | Size: 158 B |
BIN
pythonVersion/images/numbers/9.3.png
Normal file
|
After Width: | Height: | Size: 160 B |
BIN
pythonVersion/images/numbers/9.4.png
Normal file
|
After Width: | Height: | Size: 165 B |
BIN
pythonVersion/images/numbers/9.5.png
Normal file
|
After Width: | Height: | Size: 172 B |
BIN
pythonVersion/images/numbers/9.6.png
Normal file
|
After Width: | Height: | Size: 163 B |
BIN
pythonVersion/images/numbers/9.7.png
Normal file
|
After Width: | Height: | Size: 165 B |
BIN
pythonVersion/images/numbers/9.8.png
Normal file
|
After Width: | Height: | Size: 172 B |
BIN
pythonVersion/images/numbers/9.9.png
Normal file
|
After Width: | Height: | Size: 174 B |
BIN
pythonVersion/images/numbers/blank.png
Normal file
|
After Width: | Height: | Size: 129 B |
BIN
pythonVersion/images/numbers/y0.3.png
Normal file
|
After Width: | Height: | Size: 169 B |
BIN
pythonVersion/images/numbers/y0.4.png
Normal file
|
After Width: | Height: | Size: 166 B |
BIN
pythonVersion/images/numbers/y0.5.png
Normal file
|
After Width: | Height: | Size: 167 B |
BIN
pythonVersion/images/sentdex.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
pythonVersion/images/test.png
Normal file
|
After Width: | Height: | Size: 161 B |
91
pythonVersion/imgrec.py
Normal file
@@ -0,0 +1,91 @@
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
from collections import Counter
|
||||
import operator
|
||||
|
||||
def createExamples():
|
||||
numberArrayExamples = open('numArEx.txt', 'a')
|
||||
numbersWeHave = range(1,10)
|
||||
versionsWeHave = range(1,10)
|
||||
|
||||
for eachNum in numbersWeHave:
|
||||
for eachVer in versionsWeHave:
|
||||
#print str(eachNum) + '.' + str(eachVer)
|
||||
imgFilePath = 'images/numbers/' + str(eachNum) + '.' + str(eachVer) + '.png'
|
||||
ei = Image.open(imgFilePath)
|
||||
eiar = np.array(ei)
|
||||
eiar1 = str(eiar.tolist())
|
||||
|
||||
lineToWrite = str(eachNum) + '::' + eiar1 + '\n'
|
||||
numberArrayExamples.write(lineToWrite)
|
||||
|
||||
|
||||
def threshold(imageArray):
|
||||
balanceAr = []
|
||||
newAr = imageArray
|
||||
|
||||
for eachRow in imageArray:
|
||||
for eachPix in eachRow:
|
||||
avgNum = reduce(lambda x, y: x+y, eachPix[:3])/len(eachPix[:3])
|
||||
balanceAr.append(avgNum)
|
||||
|
||||
balance = reduce(lambda x, y: x + y, balanceAr)/len(balanceAr)
|
||||
|
||||
for eachRow in newAr:
|
||||
for eachPix in eachRow:
|
||||
if reduce(lambda x, y: x+y, eachPix[:3])/len(eachPix[:3]) > balance:
|
||||
eachPix[0] = 255
|
||||
eachPix[1] = 255
|
||||
eachPix[2] = 255
|
||||
eachPix[3] = 255
|
||||
else:
|
||||
eachPix[0] = 0
|
||||
eachPix[1] = 0
|
||||
eachPix[2] = 0
|
||||
eachPix[3] = 255
|
||||
|
||||
return newAr
|
||||
|
||||
def whatNumIsThis(filePath):
|
||||
matchedAr = []
|
||||
loadExamps = open('numArEx.txt', 'r').read()
|
||||
loadExamps = loadExamps.split('\n')
|
||||
|
||||
i = Image.open(filePath)
|
||||
iar = np.array(i)
|
||||
iarl = iar.tolist()
|
||||
|
||||
inQuestion = str(iarl)
|
||||
|
||||
for eachExample in loadExamps:
|
||||
if len(eachExample) > 3:
|
||||
splitEx = eachExample.split('::')
|
||||
currentNum = splitEx[0]
|
||||
currentAr = splitEx[1]
|
||||
|
||||
eachPixEx = currentAr.split('],')
|
||||
|
||||
eachPixInQ = inQuestion.split('],')
|
||||
|
||||
x=0
|
||||
|
||||
while x < len(eachPixEx):
|
||||
if eachPixEx[x] == eachPixInQ[x]:
|
||||
matchedAr.append(int(currentNum))
|
||||
|
||||
x += 1
|
||||
|
||||
#print matchedAr
|
||||
x = Counter(matchedAr)
|
||||
#print x
|
||||
numb = max(x.iteritems(), key=operator.itemgetter(1))[0]
|
||||
#print numb
|
||||
return numb, x
|
||||
|
||||
|
||||
|
||||
n, counts = whatNumIsThis('images/test.png')
|
||||
print n
|
||||
print counts
|
||||