-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw.py
More file actions
84 lines (63 loc) · 2.24 KB
/
Copy pathhw.py
File metadata and controls
84 lines (63 loc) · 2.24 KB
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
import cv2
import numpy as np
import tkinter as tk
from PIL import Image, ImageTk
import pickle
def load_obj(name ):
with open('obj/' + name + '.pkl', 'rb') as f:
return pickle.load(f)
s_dict = load_obj("storage_dict")
hw_dict= s_dict[0]
pc_dict= s_dict[1]
nm_dict = s_dict[2]
pc = {"-":0,".":1,",":2,"/":3,"\\":4,":":5,"&":6,"%":7,"^":8,"(":9,")":10,"[":11,"]":12,"@":13,"#":14,"!":15}
f = open("input.txt", "r")
ans = []
max_len = -1
for line in f:
print(line)
line = line.rstrip().lower()
start = 0
while(line[start]==" "):
start+=1
if ord(line[start])-97 in hw_dict:
im_v = hw_dict[ord(line[start])-97].copy()
elif line[start] in pc:
im_v = pc_dict[pc[line[start]]].copy()
elif line[start].isnumeric():
im_v = nm_dict[int(line[start])].copy()
for x in line[start+1::]:
if(ord(x)==32):
prev = im_v.shape[1]
space = np.zeros([im_v.shape[0],hw_dict[0].shape[1]],dtype=np.uint8)
space.fill(255)
im_v = cv2.hconcat([im_v,space])
elif(ord(x)>=97 and ord(x)<=122):
prev = im_v.shape[1]
im_v = cv2.hconcat([im_v, cv2.resize(hw_dict[ord(x)-97], (hw_dict[ord(x)-97].shape[1], im_v.shape[0])) ])
elif( x in pc):
prev = im_v.shape[1]
im_v = cv2.hconcat([im_v, cv2.resize(pc_dict[pc[x]], (pc_dict[pc[x]].shape[1], im_v.shape[0])) ])
ans.append(im_v)
if(im_v.shape[1]>max_len):
max_len = im_v.shape[1]
deficit_length = [max_len-x.shape[1] for x in ans]
hor_line = np.zeros([1,max_len],dtype=np.uint8)
im_v = ans[0]
space = np.zeros([im_v.shape[0],deficit_length[0]],dtype=np.uint8)
space.fill(255)
left_margin = np.zeros([1,max_len],dtype=np.uint8)
left_margin.fill(255)
im_v = cv2.hconcat([im_v,space])
final = cv2.vconcat([im_v,hor_line])
for i in range(1,len(ans)):
im_v = ans[i]
space = np.zeros([im_v.shape[0],deficit_length[i]],dtype=np.uint8)
space.fill(255)
im_v = cv2.hconcat([im_v,space])
final = cv2.vconcat([final,im_v,hor_line])
while True:
cv2.imshow('x', final)
if cv2.waitKey(100) == 27:
break
cv2.destroyAllWindows()