forked from tonybeltramelli/pix2code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.py
More file actions
34 lines (26 loc) · 850 Bytes
/
Copy pathUtils.py
File metadata and controls
34 lines (26 loc) · 850 Bytes
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
__author__ = 'Tony Beltramelli - www.tonybeltramelli.com'
import numpy as np
class Utils:
@staticmethod
def sparsify(label_vector, output_size):
sparse_vector = []
for label in label_vector:
sparse_label = np.zeros(output_size)
sparse_label[label] = 1
sparse_vector.append(sparse_label)
return np.array(sparse_vector)
@staticmethod
def get_preprocessed_img(img_path, image_size):
import cv2
img = cv2.imread(img_path)
img = cv2.resize(img, (image_size, image_size))
img = img.astype('float32')
img /= 255
return img
@staticmethod
def show(image):
import cv2
cv2.namedWindow("view", cv2.WINDOW_AUTOSIZE)
cv2.imshow("view", image)
cv2.waitKey(0)
cv2.destroyWindow("view")