-
Notifications
You must be signed in to change notification settings - Fork 1
/
captchaSolver.py
36 lines (28 loc) · 912 Bytes
/
captchaSolver.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
#!/usr/bin/env python
import os
import pickle
import numpy as np
from skimage.transform import resize
from cropLettersFromImage import getWords
DataDirectory = "./DataSet/"
Categories = os.listdir(DataDirectory)
filename = "finalized_model.sav"
try:
loaded_model = pickle.load(open(filename, "rb"))
except:
print("You should train model and save the model first!")
exit(0)
def getCaptchaText(Captcha):
clusters = getWords(Captcha)
text = ""
for image in clusters:
flat_data = []
img_resized = resize(image, (40, 40, 3))
flat_data.append(img_resized.flatten())
flat_data = np.array(flat_data)
y_output = loaded_model.predict(flat_data)
text += Categories[y_output[0]].replace("upper", "").replace("lower", "")
return text
Captcha = "./Golestan-Captchas/69310.gif"
text = getCaptchaText(Captcha)
print("Predicted Text Is:", text)