From dfa90ae487fb6ceeca71038e64c82eccf4d41c86 Mon Sep 17 00:00:00 2001 From: David Chatel Date: Tue, 11 Feb 2025 17:15:48 +0100 Subject: [PATCH] Added Lanczos to warpAffine --- nodes.py | 6 ++++-- utils.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nodes.py b/nodes.py index 96fa2e0..a9b1870 100644 --- a/nodes.py +++ b/nodes.py @@ -172,13 +172,15 @@ class WarpFaceBack: crop, mask, warp = list(zip(*[x[1:] for x in values])) warped_masks = [cv2.warpAffine(single_mask.numpy(), cv2.invertAffineTransform(single_warp), - image.shape[1::-1]) + image.shape[1::-1], + flags=cv2.INTER_LANCZOS4) for single_warp, single_mask in zip(warp, mask)] full_mask = np.add.reduce(warped_masks, axis=0)[...,None] swapped = np.add.reduce([ cv2.warpAffine(single_crop.cpu().numpy(), cv2.invertAffineTransform(single_warp), - image.shape[1::-1] + image.shape[1::-1], + flags=cv2.INTER_LANCZOS4 ) * single_mask[..., None] for single_crop, single_mask, single_warp in zip(crop, warped_masks, warp) ], axis=0) / np.maximum(1, full_mask) diff --git a/utils.py b/utils.py index a1897cd..5895642 100644 --- a/utils.py +++ b/utils.py @@ -119,7 +119,7 @@ class Face: T3 = np.array([[1, 0, -cx], [0, 1, -cy], [0, 0, 1]]) T4 = np.array([[1, 0, cx], [0, 1, cy], [0, 0, 1]]) N = N @ T4 @ S @ T3 - crop = cv2.warpAffine(self.img.numpy(), N, (size, size)) + crop = cv2.warpAffine(self.img.numpy(), N, (size, size), flags=cv2.INTER_LANCZOS4) crop = torch.from_numpy(crop)[None] return N, crop