Spaces:
Runtime error
Runtime error
File size: 952 Bytes
1d663f5 fdbcdcd 1d663f5 |
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 |
import cv2
import pickle as pkl
def load_dict_picklefile(dictFile):
fp=open(dictFile,'rb')
worddicts=pkl.load(fp)
fp.close()
worddicts_r = [None] * len(worddicts)
i=1
for kk, vv in worddicts.items():
if(i<len(worddicts)):
worddicts_r[vv] = kk
else:
break
i=i+1
return worddicts_r
def preprocess_img(img):
if len(img.shape)>2:
img= cv2.cvtColor(img.astype('float32'), cv2.COLOR_BGR2GRAY)
height=img.shape[0]
width=img.shape[1]
if(width<300):
result = np.ones([img.shape[0], img.shape[1]*2])*255
result[0:img.shape[0],img.shape[1]:img.shape[1]*2]=img
img=result
img=cv2.resize(img, dsize=(800,100), interpolation = cv2.INTER_AREA)
img=(img-img.min())/(img.max()-img.min())
xx_pad = np.zeros((100, 800), dtype='float32')
xx_pad[:,:] =1
xx_pad = xx_pad[None, :, :]
img=img[None, :, :]
return img, xx_pad
|