forked from hgarrereyn/OCRaaP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoder.py
49 lines (31 loc) · 1.09 KB
/
decoder.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
import numpy as np
import cv2
import image_parser
import model
import time
s = time.time()
model = model.Model(fromCheckpoint='milestones/classifier_v1.0.ckpt')
e = time.time()
print(str(e-s) + ' seconds to load model')
image = cv2.imread('decode_tests/cat.jpeg')
image = cv2.resize(image, (1000,1000), None)
image_g = cv2.imread('decode_tests/cat.jpeg', cv2.IMREAD_GRAYSCALE)
symbols, keypoints = image_parser.get_symbols(image_g)
s = time.time()
out = model.run_predict(symbols)
e = time.time()
print(str(e-s) + ' seconds to predict')
predictions = np.argmax(out[0], 1)
for i in range(len(symbols)):
cv2.imshow('a', symbols[i])
k = keypoints[i]
print(k.pt)
c = (255,0,0)
cl = ['sad', 'dead', 'at', 'hash', 'conf', 'empty', 'dot', 'dollar', 'plus', 'dash'][predictions[i]]
cv2.circle(image, (int(k.pt[0]), int(k.pt[1])), int(k.size*1.2), c, 2)
cv2.putText(image, cl, (int(k.pt[0]), int(k.pt[1]) + int(k.size)), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,0), 2)
print(cl)
#cv2.waitKey(0)
small = cv2.resize(image, (600,600), None)
cv2.imshow('a',small)
cv2.waitKey(0)