-
Notifications
You must be signed in to change notification settings - Fork 0
/
TheCapchaCracker.py
100 lines (90 loc) · 5.84 KB
/
TheCapchaCracker.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
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
import numpy as np
import copy as cp
patern_char_hash = {'000001100\n000011100\n000111100\n001101100\n011001100\n110001100\n111111110\n000001100\n000001100\n000001100\n': '4',
'000110000\n001110000\n011110000\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n011111100\n': '1',
'000110000\n001111000\n011001100\n110000110\n110000110\n110000110\n110000110\n011001100\n001111000\n000110000\n': '0',
'000110000\n001111000\n011001100\n110000110\n110000110\n110000110\n111111110\n110000110\n110000110\n110000110\n': 'A',
'000111100\n000001100\n000001100\n000001100\n000001100\n000001100\n000001100\n010001100\n011011000\n001110000\n': 'J',
'001111000\n011001100\n110000100\n110000000\n110111000\n111001100\n110000110\n110000110\n011001100\n001111000\n': '6',
'001111000\n011001100\n110000110\n000000110\n000001100\n000011000\n000110000\n001100000\n011000000\n111111110\n': '2',
'001111000\n011001100\n110000110\n011001100\n001111000\n011001100\n110000110\n110000110\n011001100\n001111000\n': '8',
'001111000\n011001100\n110000110\n110000110\n011001110\n001110110\n000000110\n010000110\n011001100\n001111000\n': '9',
'001111000\n011001100\n110000110\n110000110\n110000110\n110000110\n110000110\n110000110\n011001100\n001111000\n': 'O',
'001111000\n011001100\n110000110\n110000110\n110000110\n110000110\n110110110\n110011110\n011001100\n001111010\n': 'Q',
'001111100\n011000110\n110000000\n110000000\n110000000\n110001110\n110000110\n110000110\n011000110\n001111100\n': 'G',
'001111100\n011000110\n110000010\n110000000\n110000000\n110000000\n110000000\n110000010\n011000110\n001111100\n': 'C',
'011111000\n110001100\n000000110\n000001100\n000111000\n000001100\n000000110\n000000110\n110001100\n011111000\n': '3',
'011111100\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n011111100\n': 'I',
'011111100\n110000110\n110000000\n110000000\n011111100\n000000110\n000000110\n000000110\n110000110\n011111100\n': 'S',
'110000000\n110000000\n110000000\n110000000\n110000000\n110000000\n110000000\n110000000\n110000000\n111111100\n': 'L',
'110000110\n110000110\n011001100\n001111000\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n': 'Y',
'110000110\n110000110\n011001100\n001111000\n000110000\n000110000\n001111000\n011001100\n110000110\n110000110\n': 'X',
'110000110\n110000110\n110000110\n011001100\n011001100\n011001100\n001111000\n001111000\n000110000\n000110000\n': 'V',
'110000110\n110000110\n110000110\n110000110\n110000110\n110000110\n110000110\n110000110\n011001100\n001111000\n': 'U',
'110000110\n110000110\n110000110\n110000110\n110110110\n110110110\n110110110\n111111110\n111001110\n110000110\n': 'W',
'110000110\n110000110\n110000110\n110000110\n111111110\n110000110\n110000110\n110000110\n110000110\n110000110\n': 'H',
'110000110\n110001100\n110011000\n110110000\n111100000\n111100000\n110110000\n110011000\n110001100\n110000110\n': 'K',
'110000110\n111000110\n111100110\n111100110\n110110110\n110110110\n110011110\n110001110\n110001110\n110000110\n': 'N',
'110000110\n111001110\n111111110\n110110110\n110110110\n110110110\n110000110\n110000110\n110000110\n110000110\n': 'M',
'111111000\n110001100\n110000110\n110000110\n110000110\n110000110\n110000110\n110000110\n110001100\n111111000\n': 'D',
'111111000\n110001100\n110000110\n110001100\n111111000\n110001100\n110000110\n110000110\n110001100\n111111000\n': 'B',
'111111100\n000001100\n000001100\n000011000\n000110000\n001100000\n011000000\n110000000\n110000000\n111111100\n': 'Z',
'111111100\n110000000\n110000000\n110000000\n111111000\n110000000\n110000000\n110000000\n110000000\n111111100\n': 'E',
'111111100\n110000000\n110000000\n110111000\n111001100\n000000110\n000000110\n110000110\n011001100\n001111000\n': '5',
'111111100\n110000110\n110000110\n110000110\n111111100\n110000000\n110000000\n110000000\n110000000\n110000000\n': 'P',
'111111100\n110000110\n110000110\n110000110\n111111100\n111110000\n110011000\n110001100\n110000110\n110000110\n': 'R',
'111111110\n000000110\n000000110\n000001100\n000011000\n000110000\n001100000\n011000000\n110000000\n110000000\n': '7',
'111111110\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n000110000\n': 'T',
'111111110\n110000000\n110000000\n110000000\n111111000\n110000000\n110000000\n110000000\n110000000\n110000000\n': 'F'}
def crop_image(image):
img_new = image.copy()
return img_new[11:21,5:5+9*5]
def threshold_image(image):
img_new = cp.deepcopy(image)
for rdx, row in enumerate(image):
for cdx, col in enumerate(row):
r,g,b = image[rdx][cdx]
# print(r)
Y = 0.2126*r + 0.7152*g + 0.0722*b
# print(Y)
img_new[rdx, cdx] = (1,1,1) if Y > 0.5 else (0,0,0)
return img_new
def split_chars(image):
img_new = image.copy()
img_new = (image[:,:9], image[:,9:18], image[:,18:27], image[:,27:36], image[:,36:45])
return img_new
def hash_char(char_image):
s = ""
for line in char_image.tolist():
for pix in line:
s += '1' if pix[0] == 0 else '0'
s+= '\n'
return s
if __name__ == '__main__':
linenumber = 0
row = 0
col = 0
img_data = np.array([])
while True:
try:
line = input()
line_array = line.split(' ')
if len(line_array) == 2:
row = line_array[0]
col = line_array[1]
img_data = np.empty((int(row), int(col), 3))
else:
for i in range(len(line_array)):
r,g,b = line_array[i].split(',')
img_data[linenumber, i] = (float(r)/255.0,float(g)/255.0,float(b)/255.0)
linenumber += 1
except EOFError:
break
img_crop = crop_image(img_data)
img_tresh = threshold_image(img_crop)
split_chars = split_chars(img_tresh)
# print_in_data(split_chars[2])
output = ""
for i in range(len(split_chars)):
output += patern_char_hash[hash_char(split_chars[i])]
print(output)