2 Copyright (c) 2019-present NAVER Corp.
8 from __future__
import division
16 0.485, 0.456, 0.406), variance=(
17 0.229, 0.224, 0.225)):
19 img = in_img.copy().astype(np.float32)
21 img -= np.array([mean[0] * 255.0, mean[1] * 255.0,
22 mean[2] * 255.0], dtype=np.float32)
23 img /= np.array([variance[0] * 255.0, variance[1] * 255.0,
24 variance[2] * 255.0], dtype=np.float32)
30 0.485, 0.456, 0.406), variance=(
31 0.229, 0.224, 0.225)):
37 img = np.clip(img, 0, 255).astype(np.uint8)
42 height, width, channel = img.shape
45 target_size = mag_ratio * max(height, width)
48 if target_size > square_size:
49 target_size = square_size
51 ratio = target_size / max(height, width)
53 target_h, target_w =
int(height * ratio),
int(width * ratio)
54 proc = cv2.resize(img, (target_w, target_h), interpolation=interpolation)
57 target_h32, target_w32 = target_h, target_w
58 if target_h % 32 != 0:
59 target_h32 = target_h + (32 - target_h % 32)
60 if target_w % 32 != 0:
61 target_w32 = target_w + (32 - target_w % 32)
62 resized = np.zeros((target_h32, target_w32, channel), dtype=np.float32)
63 resized[0:target_h, 0:target_w, :] = proc
64 target_h, target_w = target_h32, target_w32
66 size_heatmap = (
int(target_w / 2),
int(target_h / 2))
68 return resized, ratio, size_heatmap
72 img = (np.clip(img, 0, 1) * 255).astype(np.uint8)
73 img = cv2.applyColorMap(img, cv2.COLORMAP_JET)