Tayaba171 commited on
Commit
1d663f5
1 Parent(s): 611b927

Create data.py

Browse files
Files changed (1) hide show
  1. data.py +39 -0
data.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import pickle as pkl
3
+
4
+ def load_dict_picklefile():
5
+ fp=open('vocabulary.pkl','rb')
6
+ worddicts=pkl.load(fp)
7
+ fp.close()
8
+ worddicts_r = [None] * len(worddicts)
9
+ i=1
10
+ for kk, vv in worddicts.items():
11
+ if(i<len(worddicts)):
12
+ worddicts_r[vv] = kk
13
+ else:
14
+ break
15
+ i=i+1
16
+ return worddicts_r
17
+
18
+ def preprocess_img(img):
19
+ if len(img.shape)>2:
20
+ img= cv2.cvtColor(img.astype('float32'), cv2.COLOR_BGR2GRAY)
21
+ height=img.shape[0]
22
+ width=img.shape[1]
23
+
24
+ if(width<300):
25
+ result = np.ones([img.shape[0], img.shape[1]*2])*255
26
+ result[0:img.shape[0],img.shape[1]:img.shape[1]*2]=img
27
+ img=result
28
+
29
+ img=cv2.resize(img, dsize=(800,100), interpolation = cv2.INTER_AREA)
30
+ img=(img-img.min())/(img.max()-img.min())
31
+ xx_pad = np.zeros((100, 800), dtype='float32')
32
+ xx_pad[:,:] =1
33
+
34
+ xx_pad = xx_pad[None, :, :]
35
+ img=img[None, :, :]
36
+ return img, xx_pad
37
+
38
+
39
+