svjack/ControlNet-Pose-Chinese
5
1import numpy as np2import cv23import os4 5 6annotator_ckpts_path = os.path.join(os.path.dirname(__file__), 'ckpts')7 8 9def HWC3(x):10 assert x.dtype == np.uint811 if x.ndim == 2:12 x = x[:, :, None]13 assert x.ndim == 314 H, W, C = x.shape15 assert C == 1 or C == 3 or C == 416 if C == 3:17 return x18 if C == 1:19 return np.concatenate([x, x, x], axis=2)20 if C == 4:21 color = x[:, :, 0:3].astype(np.float32)22 alpha = x[:, :, 3:4].astype(np.float32) / 255.023 y = color * alpha + 255.0 * (1.0 - alpha)24 y = y.clip(0, 255).astype(np.uint8)25 return y26 27 28def resize_image(input_image, resolution):29 H, W, C = input_image.shape30 H = float(H)31 W = float(W)32 k = float(resolution) / min(H, W)33 H *= k34 W *= k35 H = int(np.round(H / 64.0)) * 6436 W = int(np.round(W / 64.0)) * 6437 img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)38 return img39 