-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (38 loc) · 1.12 KB
/
main.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
from contextlib import contextmanager
import cv2
import imutils
from OCR import get_letters, predict_letters, get_matching
import cProfile
import pstats
@contextmanager
def profiler_code():
pr = cProfile.Profile()
try:
pr.enable()
yield
finally:
pr.disable()
pr.print_stats(sort="tottime")
def show_img(let_list, img):
green = (0, 255, 0)
red = (255, 0, 0)
i = 0
for let in let_list:
if let.rownum % 2 == 0:
color = red
else:
color = green
cv2.rectangle(img, (let.x, let.y), (let.x + let.w, let.y + let.h), color, 1)
cv2.putText(img, str(i), (let.x, let.y), cv2.FONT_HERSHEY_SIMPLEX, 0.3, (255, 0, 0), 1)
i+=1
cv2.imshow(f'letter', img)
cv2.waitKey(0)
if '__main__' == __name__:
# with profiler_code():
img_path = 'images/mz2.jpg'
image = cv2.imread(img_path)
img_resized = imutils.resize(image, width=1200)
letter_list = get_letters(image)
letter_list = predict_letters(letter_list, image, cnn=True)
get_matching(letter_list, image)
show_img(letter_list, image)