-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardscript
More file actions
149 lines (122 loc) · 3.67 KB
/
hardscript
File metadata and controls
149 lines (122 loc) · 3.67 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
mechanize.Browser().retrieve(url, 'captcha.jpg')
from PIL import Image
import hashlib, time, os, math, _imaging
img = Image.open(fic)
img = img.convert("RGBA")
pixdata = img.load()
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x, y][0] ; 0:
pixdata[x, y] = (255, 255, 255, 255)
img = img.resize((1000, 300), Image.NEAREST)
im2 = Image.new("P",img.size,255)
im = img.convert("P")
pas = 5
alone = True
for x in range(0,im.size[1],pas):
for y in range(0,im.size[0],pas):
if im.getpixel((y,x)) == 0:
for i in range(-pas,pas,1):
for j in range(-pas,pas,1):
if (y+i ;= 0 and x+j >;= 0):
if im.getpixel((y+i,x+j)):
alone = False
for i in range(-pas,pas,1):
for j in range(-pas,pas,1):
if (y+i ;= 0 and x+j >;= 0):
if not alone:
im2.putpixel((y+i,x+j),0)
alone = True
saut = 9
inletter = False
foundletter=False
start_ab = 0
end_ab = 0
start_or = im2.size[1]-1
end_or = 0
size = 0
debut = True
letters = []
for y in range(0,im2.size[0],saut): # slice across
for x in range(0,im2.size[1],1): # slice down
pix = im2.getpixel((y,x))
if pix != 255:
start_or = min(start_or,x)
end_or = max(end_or,x)
inletter = True
if foundletter == False and inletter == True:
foundletter = True
start_ab = y
if foundletter == True and inletter == False:
foundletter = False
end_ab = y
size = max(size,end_ab)
letters.append((start_ab,end_ab,start_or,end_or))
start_or = im2.size[1]-1
end_or = 0
inletter=False
class VectorCompare:
def magnitude(self,concordance):
if type(concordance) != dict:
raise ValueError('Supplied Argument should be of type dict')
total = 0
for word,count in concordance.iteritems():
total += count ** 2
return math.sqrt(total)
def relation(self,concordance1, concordance2):
if type(concordance1) != dict:
raise ValueError('Supplied Argument 1 should be of type dict')
if type(concordance2) != dict:
raise ValueError('Supplied Argument 2 should be of type dict')
relevance = 0
topvalue = 0
for word, count in concordance1.iteritems():
if concordance2.has_key(word):
topvalue += count * concordance2[word]
if (self.magnitude(concordance1) * self.magnitude(concordance2)) != 0:
return topvalue / (self.magnitude(concordance1) * self.magnitude(concordance2))
else:
return 0
def concordance(self,document):
if type(document) != str:
raise ValueError('Supplied Argument should be of type string')
con = {}
for word in document.split(' '):
if con.has_key(word):
con[word] = con[word] + 1
else:
con[word] = 1
return con
def buildvector(im):
d1 = {}
count = 0
for i in im.getdata():
d1[count] = i
count += 1
return d1
v = VectorCompare()
iconset = ['1','2','3','4','5','6','7','8','a','b','c','d','e','f','h','j','k','l','m','n','p','q','r','t','u','v','w','x','y','z','']
imageset = []
for letter in iconset:
for img in os.listdir('./iconset/%s/'%(letter)):
temp = []
temp.append(buildvector(Image.open("./iconset/%s/%s"%(letter,img))))
imageset.append({letter:temp})
count = 0
res = ""
for letter in letters:
m = hashlib.md5()
im3 = im2.crop(( letter[0] , letter[2], letter[1],letter[3] ))
m.update("%s%s"%(time.time(),count))
#im3.save("./%d_%s.gif"%(count,m.hexdigest()))
guess = []
for image in imageset:
for x,y in image.iteritems():
if (x == "''"):
x = ''
if len(y) != 0:
guess.append( ( v.relation(y[0],buildvector(im3)),x) )
guess.sort(reverse=True)
res += guess[0][1]
count += 1
return res