-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathverification_code2text.py
111 lines (86 loc) · 2.88 KB
/
verification_code2text.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
101
102
103
104
105
106
107
108
import os
import sys
#============================================
# my function / class
import platform
if 'Windows' in platform.platform():
PATH = "\\".join( os.path.abspath(__file__).split('\\')[:-1])
else:
PATH = "/".join( os.path.abspath(__file__).split('/')[:-1])
sys.path.append(PATH)
sys.path.append(PATH)
#============================================
import cv2
import numpy as np
import matplotlib.pyplot as plt
from load_model import load_model
#===============================================================
'''
import random
file_path = '{}/{}/'.format(PATH,'test_data')
train_image_path = [file_path + i for i in os.listdir(file_path+'/')]
image_name = train_image_path[random.sample( range(100) ,1)[0]]
image = cv2.imread(image_name)
plt.imshow(image)
text = main(image)
print(text)
'''
def validation(test_path):
file_path = 'success_vcode'
os.chdir(PATH)
if file_path not in os.listdir():
os.makedirs(file_path)
if 'Windows' in platform.platform():
file_path = '{}\\{}\\'.format(PATH,'success_vcode')
test_image_path = [file_path + i for i in os.listdir(file_path+'\\')]
else:
file_path = '{}/{}/'.format(PATH,'success_vcode')
test_image_path = [file_path + i for i in os.listdir(file_path+'/')]
sum_count = len(test_image_path)
data_set = np.ndarray(( sum_count , 60, 200,3), dtype=np.uint8)
i=0
#s = time.time()
while( i < sum_count ):
image_name = test_image_path[i]
image = cv2.imread(image_name)
data_set[i] = image
i=i+1
if i%50 == 0: print('Processed {} of {}'.format(i, sum_count ) )
#--------------------------------------------------
real_labels = []
for text in test_image_path:
if 'Windows' in platform.platform():
text = text.split('\\')
else:
text = text.split('/')
text = text[len(text)-1]
text_set = text.replace('.png','')
real_labels.append(text_set)
image = cv2.imread(image_name)
plt.imshow(image)
text = main(image)
print(text)
def main(image):
#def verification_code_to_text(image_name):
#os_path = os.getcwd()
def change_character(pred_prob):
total_set = []
for i in range(65, 91):
total_set.append( chr(i) )
for i in range(10):
total_set.append(str(i))
total_set.append('')
for i in range(len(pred_prob)):
if pred_prob[i] == max( pred_prob ):
value = (total_set[i])
return value
train_set = np.ndarray(( 1 , 60, 200,3), dtype=np.uint8)
#image = cv2.imread(image_name)
train_set[0] = image
model = load_model()
result = model.predict(train_set)
resultlist = ''
for i in range(len(result)):
resultlist += change_character(result[i][0])
#os.chdir(os_path)
return resultlist