CoolFace
Apppublic

luzasd/forensic

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
utils.py16 linesDownload Raw Back to root
1import numpy as np
2import cv2
3
4def resize_image(img, shape):
5    return cv2.resize(img, (shape[1], shape[0]), interpolation=cv2.INTER_LINEAR)
6
7def 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
16