Last active
November 26, 2021 22:58
-
-
Save mrtj/d16f55bcf17c8ee2fc8358d3e86bb2cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
class Application(panoramasdk.node): | |
# ... | |
def preprocess(self, img, input_size, swap=(2, 0, 1)): | |
if len(img.shape) == 3: | |
padded_img = np.ones((input_size[0], input_size[1], 3), dtype=np.uint8) * 114 | |
else: | |
padded_img = np.ones(input_size, dtype=np.uint8) * 114 | |
r = min(input_size[0] / img.shape[0], input_size[1] / img.shape[1]) | |
resized_img = cv2.resize( | |
img, | |
(int(img.shape[1] * r), int(img.shape[0] * r)), | |
interpolation=cv2.INTER_LINEAR, | |
).astype(np.uint8) | |
padded_img[: int(img.shape[0] * r), : int(img.shape[1] * r)] = resized_img | |
padded_img = padded_img.transpose(swap) | |
padded_img = np.ascontiguousarray(padded_img, dtype=np.float32) | |
return padded_img, r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment