-
Notifications
You must be signed in to change notification settings - Fork 2
/
decode_captcha.py
36 lines (30 loc) · 975 Bytes
/
decode_captcha.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
import cv2
import os
import segmentation as seg
from tensorflow.keras.models import load_model
import numpy as np
model=load_model('model.h5',compile=True)
classes='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
def predict(image):
image=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
img_paths=seg.extract_character(image)
output=' '
for i in img_paths:
m=[]
img=cv2.imread(i,cv2.IMREAD_GRAYSCALE)
img = cv2.bitwise_not(img)
img=np.reshape(img,(28,28,1))/255
m.append(img)
m=np.array(m)
result=np.argmax(model.predict(m))
output+=classes[result]
return output
def test():
#Enter filenames to be tested in image_paths after adding them to this folder
image_paths=['Sample_captchas/567.jpeg']
for i in image_paths:
image=cv2.imread(i)
captcha_decoded=predict(image)
print(captcha_decoded)
if __name__=='__main__':
test()