Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathimagerec9.py
More file actions
Latest commit
109 lines (73 loc) · 2.63 KB
/
Copy pathimagerec9.py
File metadata and controls
109 lines (73 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
fromPILimportImage
importnumpyasnp
importmatplotlib.pyplotasplt
importtime
####awwww yeeeeuuhhhhhhh#####
fromcollectionsimportCounter
defcreateExamples():
numberArrayExamples=open('numArEx.txt','a')
numbersWeHave=range(1,10)
foreachNuminnumbersWeHave:
forfurtherNuminnumbersWeHave:
print(str(eachNum)+'.'+str(furtherNum))
imgFilePath='images/numbers/'+str(eachNum)+'.'+str(furtherNum)+'.png'
ei=Image.open(imgFilePath)
eiar=np.array(ei)
eiarl=str(eiar.tolist())
#time.sleep(555)
lineToWrite=str(eachNum)+'::'+eiarl+'\n'
numberArrayExamples.write(lineToWrite)
defthreshold(imageArray):
balanceAr= []
newAr=imageArray
foreachPartinimageArray:
forthePartsineachPart:
avgNum=reduce(lambdax, y: x+y, theParts[:3]) /len(theParts[:3])
balanceAr.append(avgNum)
balance=reduce(lambdax, y: x+y, balanceAr) /len(balanceAr)
foreachRowinnewAr:
foreachPixineachRow:
ifreduce(lambdax, 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
returnnewAr
defwhatNumIsThis(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)
#dont forget to clear out that array!!!!#
foreachExampleinloadExamps:
try:
splitEx=eachExample.split('::')
currentNum=splitEx[0]
currentAr=splitEx[1]
#print currentAr
#okay not the most professional way to do it, but
#since we are not blurring, and we are going pixil by pix,
#this will be fine and very simple.
eachPixEx=currentAr.split('],')
eachPixInQ=inQuestion.split('],')
x=0
whilex<len(eachPixEx):
ifeachPixEx[x] ==eachPixInQ[x]:
matchedAr.append(int(currentNum))
x+=1
exceptExceptionase:
print(str(e))
print(matchedAr)
x=Counter(matchedAr)
print(x)
print(x[0])
whatNumIsThis('images/test.png')
#createExamples()