forked from Sadhanandh/Captcha-Crack
/
enhancer.py
executable file
·64 lines (55 loc) · 1.26 KB
/
enhancer.py
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
#!/usr/bin/python
import Image
import sys
import os
val =0
if len(sys.argv)>1:
inp = sys.argv[1]
else :
inp = 'test.gif'
if len(sys.argv)>2:
txt = sys.argv[2]
else :
txt = 'none'
if len(sys.argv)>3:
cn = sys.argv[3]
else :
cn = ""
#im = Image.open('%d.gif'%(val))
im = Image.open("input"+cn+"/"+inp)
im = im.convert("RGB")
start =6
en = im.size[0]-1
box = (start,0,en,25)
img1 = im.crop(box)
x = img1.load()
for i in range(en-start):
for j in range(25):
if x[i,j] == (102,102,102):
x[i,j] = (255,255,255)
elif x[i,j] ==(153,153,153):
x[i,j] = (255,255,255)
else:
x[i,j] = (0,0,0)
img1 = img1.convert('1')
filn = "Score.txt"
if not os.path.exists('output'+cn):
os.makedirs('output'+cn)
img1.save(os.path.join('output'+cn,inp))
if not os.path.exists('text_output'+cn):
os.makedirs('text_output'+cn)
dat = open(os.path.join('text_output'+cn,inp[:inp.rfind('.')]+'.txt'),"w")
filler = open(os.path.join(".",filn),"a")
from pytesser import pytesser
text = pytesser.image_file_to_string(os.path.join('output'+cn,inp))
print text.strip('\n')
dat.write("Guessed "+text.strip('\n')+'\n')
dat.write("Actual "+txt)
if txt==text.strip('\n'):
dat.write("Success!")
filler.write("1"+"\n")
else:
dat.write("Failed!")
filler.write("0"+"\n")
dat.close()
filler.close()