luzasd commited on
Commit
a7fa603
·
verified ·
1 Parent(s): ae559cf

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +15 -0
utils.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import cv2
3
+
4
+ def resize_image(img, shape):
5
+ return cv2.resize(img, (shape[1], shape[0]), interpolation=cv2.INTER_LINEAR)
6
+
7
+ def text_to_image(text, img_shape, font=cv2.FONT_HERSHEY_SIMPLEX, font_scale=3, thickness=5):
8
+ text_size = cv2.getTextSize(text, font, font_scale, thickness)[0]
9
+ text_x = (img_shape[1] - text_size[0]) // 2
10
+ text_y = (img_shape[0] + text_size[1]) // 2
11
+
12
+ img_wm = np.zeros(img_shape, dtype=np.uint8)
13
+ cv2.putText(img_wm, text, (text_x, text_y), font, font_scale, (255, 255, 255), thickness)
14
+
15
+ return img_wm